Last active
July 6, 2017 08:33
-
-
Save agoalofalife/f09465931b8354b158280646952bbb39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use League\Pipeline\Pipeline; | |
class NumberHandler | |
{ | |
public function __invoke($value) | |
{ | |
if (gettype($value) == 'float') | |
{ | |
return round($value); | |
} | |
return $value; | |
} | |
} | |
class StringHandler { | |
public function __invoke($value) | |
{ | |
if (gettype($value) == 'string') | |
{ | |
return strtoupper($value); | |
} | |
return $value; | |
} | |
} | |
class ArrayHandler { | |
public function some($value) | |
{ | |
if (gettype($value) == 'array') | |
{ | |
sort($value); | |
return $value; | |
} | |
return $value; | |
} | |
} | |
$process = (new Pipeline) | |
->pipe(new NumberHandler) | |
->pipe(new StringHandler) | |
->pipe([new ArrayHandler, 'some']); | |
$result = $process->process( [33,2,1,234] ); | |
dd($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment