Skip to content

Commit

Permalink
[5.2] Allow objects to be passed as pipes
Browse files Browse the repository at this point in the history
Allows following code to be executed, very useful in case pipes require some complex constructing or already exist.
```php
(new Pipeline($app))->send($subject)->through([new A, new B])->via('pipe_method')->then(...);
```
  • Loading branch information
Roman Kinyakin committed Apr 7, 2016
1 parent 8495627 commit 229c3fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Illuminate/Pipeline/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ protected function getSlice()
// the appropriate method and arguments, returning the results back out.
if ($pipe instanceof Closure) {
return call_user_func($pipe, $passable, $stack);
} else {
} elseif (! is_object($pipe)) {
list($name, $parameters) = $this->parsePipeString($pipe);

return call_user_func_array([$this->container->make($name), $this->method],
array_merge([$passable, $stack], $parameters));
$pipe = $this->container->make($name);
$parameters = array_merge([$passable, $stack], $parameters);
} else {
$parameters = [$passable, $stack];
}

return call_user_func_array([$pipe, $this->method], $parameters);
};
};
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Pipeline/PipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public function testPipelineBasicUsage()
unset($_SERVER['__test.pipe.two']);
}

public function testPipelineUsageWithObjects()
{
$result = (new Pipeline(new Illuminate\Container\Container))
->send('foo')
->through([new PipelineTestPipeOne])
->then(function ($piped) {
return $piped;
});

$this->assertEquals('foo', $result);
$this->assertEquals('foo', $_SERVER['__test.pipe.one']);

unset($_SERVER['__test.pipe.one']);
}

public function testPipelineUsageWithParameters()
{
$parameters = ['one', 'two'];
Expand Down

0 comments on commit 229c3fa

Please sign in to comment.