|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author stev leibelt <[email protected]> |
|
4
|
|
|
* @since 2014-11-07 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Net\Bazzline\Component\ProcessPipe; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ProcessPipe |
|
11
|
|
|
* @package Net\Bazzline\Component\ProcessPipe |
|
12
|
|
|
*/ |
|
13
|
|
|
class Pipe implements PipeInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var array|ExecutableInterface[] */ |
|
16
|
|
|
private $processes; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Adds one or more process to the pipe |
|
20
|
|
|
* |
|
21
|
|
|
* @param ExecutableInterface $process - or more |
|
22
|
|
|
* @param ExecutableInterface $_ [optional] |
|
23
|
|
|
* @throws InvalidArgumentException |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(ExecutableInterface $process = null, $_ = null) |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$this->processes = array(); |
|
28
|
|
|
|
|
29
|
|
|
if (func_num_args() > 0) { |
|
30
|
|
|
call_user_func_array(array($this, 'pipe'), func_get_args()); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param mixed $input |
|
36
|
|
|
* @return mixed |
|
37
|
|
|
* @throws ExecutableException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function execute($input = null) |
|
40
|
|
|
{ |
|
41
|
|
|
foreach ($this->processes as $process) { |
|
42
|
|
|
$input = $process->execute($input); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $input; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Adds one or more process to the pipe |
|
50
|
|
|
* |
|
51
|
|
|
* @param ExecutableInterface $process - or more |
|
52
|
|
|
* @param ExecutableInterface $_ [optional] |
|
53
|
|
|
* @throws InvalidArgumentException |
|
54
|
|
|
* @return $this |
|
55
|
|
|
*/ |
|
56
|
|
|
public function pipe(ExecutableInterface $process, $_ = null) |
|
57
|
|
|
{ |
|
58
|
|
|
foreach (func_get_args() as $index => $process) { |
|
59
|
|
|
if ($process instanceof ExecutableInterface) { |
|
60
|
|
|
$this->processes[] = $process; |
|
61
|
|
|
} else { |
|
62
|
|
|
$message = 'Argument ' . $index . ' passed to ' . __METHOD__ . |
|
63
|
|
|
'() must implement interface ' . |
|
64
|
|
|
'Net\Bazzline\Component\ProcessPipe\ExecutableInterface' . |
|
65
|
|
|
', instance of ' . get_class($process) . ' given'; |
|
66
|
|
|
throw new InvalidArgumentException($message); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.