1 | <?php |
||
18 | class Pipeline |
||
19 | { |
||
20 | /** |
||
21 | * DisconnectStage |
||
22 | * |
||
23 | * @var PipelineStageInterface |
||
24 | */ |
||
25 | private $disconnectStage; |
||
26 | |||
27 | /** |
||
28 | * Connect stage |
||
29 | * |
||
30 | * @var PipelineStageInterface |
||
31 | */ |
||
32 | private $connectStage; |
||
33 | |||
34 | /** |
||
35 | * PipelineStageInterface |
||
36 | * |
||
37 | * @var PipelineStageInterface[] |
||
38 | */ |
||
39 | private $stages; |
||
40 | |||
41 | /** |
||
42 | * Pipeline constructor |
||
43 | * |
||
44 | * @param PipelineStageInterface $connectStage Connect stage |
||
45 | * @param PipelineStageInterface[] $stages Pipeline stages |
||
46 | * @param PipelineStageInterface $disconnectStage Disconnect stages |
||
47 | */ |
||
48 | 67 | public function __construct( |
|
57 | |||
58 | /** |
||
59 | * Process I/O operations on sockets |
||
60 | * |
||
61 | * @param SocketBag $socketBag Socket bag |
||
62 | * |
||
63 | * @return void |
||
64 | * @throws \Exception |
||
65 | */ |
||
66 | 67 | public function process(SocketBag $socketBag) |
|
67 | { |
||
68 | do { |
||
69 | 67 | $activeOperations = $this->connectStage->processStage($socketBag->getItems()); |
|
70 | 59 | if (!$activeOperations) { |
|
71 | 29 | break; |
|
72 | } |
||
73 | |||
74 | 53 | foreach ($this->stages as $stage) { |
|
75 | 53 | $activeOperations = $stage->processStage($activeOperations); |
|
76 | 27 | } |
|
77 | 25 | } while (true); |
|
78 | 29 | } |
|
79 | |||
80 | /** |
||
81 | * Disconnect given list of sockets |
||
82 | * |
||
83 | * @param RequestDescriptor[] $items Sockets' operations |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | 11 | public function disconnectSockets(array $items) |
|
91 | } |
||
92 |