1 | <?php |
||
22 | class RequestDescriptor implements StreamResourceInterface, EventHandlerInterface |
||
23 | { |
||
24 | /** |
||
25 | * Socket for this operation |
||
26 | * |
||
27 | * @var SocketInterface |
||
28 | */ |
||
29 | private $socket; |
||
30 | |||
31 | /** |
||
32 | * Key-value pairs with meta information |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $metadata; |
||
37 | |||
38 | /** |
||
39 | * Event handler object |
||
40 | * |
||
41 | * @var EventHandlerInterface |
||
42 | */ |
||
43 | private $handlers; |
||
44 | |||
45 | /** |
||
46 | * Flag whether this socket request is running |
||
47 | * |
||
48 | * @var bool |
||
49 | */ |
||
50 | private $isRunning; |
||
51 | |||
52 | /** |
||
53 | * Operation to perform on socket |
||
54 | * |
||
55 | * @var OperationInterface |
||
56 | */ |
||
57 | private $operation; |
||
58 | |||
59 | /** |
||
60 | * Flag if this socket is postponed |
||
61 | * |
||
62 | * @var bool |
||
63 | */ |
||
64 | private $isPostponed = false; |
||
65 | |||
66 | /** |
||
67 | * RequestDescriptor constructor. |
||
68 | * |
||
69 | * @param SocketInterface $socket Socket object |
||
70 | * @param OperationInterface $operation Operation to perform on socket |
||
71 | * @param array $metadata Metadata |
||
72 | * @param EventHandlerInterface $handlers Handlers for this socket |
||
73 | */ |
||
74 | 158 | public function __construct( |
|
86 | |||
87 | /** |
||
88 | * Return Operation |
||
89 | * |
||
90 | * @return OperationInterface |
||
91 | */ |
||
92 | 99 | public function getOperation() |
|
96 | |||
97 | /** |
||
98 | * Sets Operation |
||
99 | * |
||
100 | * @param OperationInterface $operation New operation |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | 49 | public function setOperation(OperationInterface $operation) |
|
108 | |||
109 | /** |
||
110 | * Initialize data before request |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | 158 | public function initialize() |
|
118 | |||
119 | /** |
||
120 | * Return flag whether request is running |
||
121 | * |
||
122 | * @return boolean |
||
123 | */ |
||
124 | 127 | public function isRunning() |
|
128 | |||
129 | /** |
||
130 | * Sets running flag |
||
131 | * |
||
132 | * @param boolean $isRunning New value for IsRunning |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | 98 | public function setRunning($isRunning) |
|
140 | |||
141 | /** |
||
142 | * Return Socket |
||
143 | * |
||
144 | * @return SocketInterface |
||
145 | */ |
||
146 | 126 | public function getSocket() |
|
150 | |||
151 | /** {@inheritdoc} */ |
||
152 | 48 | public function getStreamResource() |
|
156 | |||
157 | /** |
||
158 | * Return key-value array with metadata |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | 145 | public function getMetadata() |
|
166 | |||
167 | /** |
||
168 | * Set metadata for given socket |
||
169 | * |
||
170 | * @param string|array $key Either string or key-value array of metadata. If string, then value must be |
||
171 | * passed in third argument, if array, then third argument will be ignored |
||
172 | * @param mixed $value Value for key or null, if $key is array |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | 140 | public function setMetadata($key, $value = null) |
|
187 | |||
188 | /** {@inheritdoc} */ |
||
189 | 125 | public function invokeEvent(Event $event) |
|
195 | |||
196 | /** |
||
197 | * Completes processing this socket in event loop, but keep this socket connection opened. Applicable |
||
198 | * only to persistent sockets, all other socket types are ignored by this method. |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | 6 | public function postpone() |
|
210 | |||
211 | /** |
||
212 | * Return true, if this socket shouldn't be processed by executor engine |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | 112 | public function isPostponed() |
|
220 | } |
||
221 |