1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
<?php
namespace Net\Bazzline\Component\ProcessPipe;
class Pipe implements PipeInterface
{
private $processes;
public function __construct(ExecutableInterface $process = null, $_ = null)
{
$this->processes = array();
if (func_num_args() > 0) {
call_user_func_array(array($this, 'pipe'), func_get_args());
}
}
public function execute($input = null)
{
foreach ($this->processes as $process) {
$input = $process->execute($input);
}
return $input;
}
public function pipe(ExecutableInterface $process, $_ = null)
{
foreach (func_get_args() as $index => $process) {
if ($process instanceof ExecutableInterface) {
$this->processes[] = $process;
} else {
$message = 'Argument ' . $index . ' passed to ' . __METHOD__ .
'() must implement interface ' .
'Net\Bazzline\Component\ProcessPipe\ExecutableInterface' .
', instance of ' . get_class($process) . ' given';
throw new InvalidArgumentException($message);
}
}
return $this;
}
}