1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Async sockets |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
namespace AsyncSockets\RequestExecutor\Pipeline; |
11
|
|
|
|
12
|
|
|
use AsyncSockets\RequestExecutor\ExecutionContext; |
13
|
|
|
use AsyncSockets\RequestExecutor\RequestExecutorInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ExcludedOperationsStage |
17
|
|
|
*/ |
18
|
|
|
class ExcludedOperationsStage extends AbstractStage |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Stages for processing successful descriptors |
22
|
|
|
* |
23
|
|
|
* @var PipelineStageInterface[] |
24
|
|
|
*/ |
25
|
|
|
private $stages; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AbstractStage constructor. |
29
|
|
|
* |
30
|
|
|
* @param RequestExecutorInterface $executor Request executor |
31
|
|
|
* @param EventCaller $eventCaller Event caller |
32
|
|
|
* @param ExecutionContext $executionContext Execution context |
33
|
|
|
* @param PipelineStageInterface[] $stages Stages for success way |
34
|
|
|
*/ |
35
|
68 |
|
public function __construct( |
36
|
|
|
RequestExecutorInterface $executor, |
37
|
|
|
EventCaller $eventCaller, |
38
|
|
|
ExecutionContext $executionContext, |
39
|
|
|
array $stages |
40
|
|
|
) { |
41
|
68 |
|
parent::__construct($executor, $eventCaller, $executionContext); |
42
|
68 |
|
$this->stages = $stages; |
43
|
68 |
|
} |
44
|
|
|
|
45
|
|
|
/** {@inheritdoc} */ |
46
|
54 |
|
public function processStage(array $requestDescriptors) |
47
|
|
|
{ |
48
|
54 |
|
$currentOperations = $requestDescriptors; |
49
|
54 |
|
foreach ($this->stages as $stage) { |
50
|
54 |
|
$currentOperations = $stage->processStage($currentOperations); |
51
|
54 |
|
} |
52
|
|
|
|
53
|
28 |
|
foreach ($requestDescriptors as $key => $descriptor) { |
54
|
28 |
|
if (in_array($descriptor, $currentOperations, true)) { |
55
|
20 |
|
unset($requestDescriptors[ $key]); |
56
|
20 |
|
} |
57
|
28 |
|
} |
58
|
|
|
|
59
|
28 |
|
return $requestDescriptors; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|