1 | <?php |
||
23 | abstract class AbstractOobHandler implements IoHandlerInterface |
||
24 | { |
||
25 | /** |
||
26 | * Operation to descriptor state map |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private static $stateMap = [ |
||
31 | OperationInterface::OPERATION_READ => RequestDescriptor::RDS_READ, |
||
32 | OperationInterface::OPERATION_WRITE => RequestDescriptor::RDS_WRITE, |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 108 | final public function handle( |
|
39 | RequestDescriptor $descriptor, |
||
40 | RequestExecutorInterface $executor, |
||
41 | EventHandlerInterface $eventHandler |
||
42 | ) { |
||
43 | 108 | $result = $this->handleOobData($descriptor, $executor, $eventHandler); |
|
44 | 108 | if ($result) { |
|
45 | 6 | return $result; |
|
46 | } |
||
47 | |||
48 | 103 | $state = $this->getInvokeState($descriptor->getOperation()); |
|
49 | 103 | if ($descriptor->hasState($state)) { |
|
50 | 98 | $descriptor->clearState($state); |
|
51 | |||
52 | 98 | $result = $this->handleOperation($descriptor, $executor, $eventHandler); |
|
53 | 57 | } |
|
54 | |||
55 | 62 | return $result; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Process given operation |
||
60 | * |
||
61 | * @param RequestDescriptor $descriptor Request descriptor |
||
62 | * @param RequestExecutorInterface $executor Executor, processing operation |
||
63 | * @param EventHandlerInterface $eventHandler Event handler for this operation |
||
64 | * |
||
65 | * @return OperationInterface|null Next operation to pass in socket. Return null, |
||
66 | * if next operation is not required. Return $operation parameter, if operation is not completed yet |
||
67 | */ |
||
68 | abstract protected function handleOperation( |
||
69 | RequestDescriptor $descriptor, |
||
70 | RequestExecutorInterface $executor, |
||
71 | EventHandlerInterface $eventHandler |
||
72 | ); |
||
73 | |||
74 | /** |
||
75 | * Return state which should invoke this operation |
||
76 | * |
||
77 | * @param OperationInterface $operation Operation object |
||
78 | * |
||
79 | * @return int RequestDescriptor::RDS_* constant |
||
80 | */ |
||
81 | 103 | private function getInvokeState(OperationInterface $operation) |
|
87 | |||
88 | /** |
||
89 | * Handle OOB data |
||
90 | * |
||
91 | * @param RequestDescriptor $descriptor Request descriptor |
||
92 | * @param RequestExecutorInterface $executor Executor, processing operation |
||
93 | * @param EventHandlerInterface $eventHandler Event handler for this operation |
||
94 | * |
||
95 | * @return OperationInterface|null Operation to return to user or null to continue normal processing |
||
96 | */ |
||
97 | 108 | private function handleOobData( |
|
124 | } |
||
125 |