Skip to content

Instantly share code, notes, and snippets.

@agoalofalife
Last active July 6, 2017 08:33
Show Gist options
  • Save agoalofalife/f09465931b8354b158280646952bbb39 to your computer and use it in GitHub Desktop.
Save agoalofalife/f09465931b8354b158280646952bbb39 to your computer and use it in GitHub Desktop.
<?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