1 | <?php |
||
29 | abstract class Processor implements ProcessorInterface, LoggerAwareInterface, StorageStackAwareInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var array Procedures |
||
33 | */ |
||
34 | protected $procedures = array(); |
||
35 | |||
36 | /** |
||
37 | * @var StorageStack Storage stack |
||
38 | */ |
||
39 | protected $stack; |
||
40 | |||
41 | /** |
||
42 | * @var LoggerInterface Logger |
||
43 | */ |
||
44 | protected $logger; |
||
45 | |||
46 | 15 | public function __construct() |
|
47 | { |
||
48 | 15 | $this->stack = new StorageStack(array( |
|
49 | 15 | 'global' => new InMemoryStorage(), |
|
50 | 15 | )); |
|
51 | 15 | } |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 10 | public function addProcedure(Procedure $procedure) |
|
57 | { |
||
58 | 10 | $this->procedures[] = $procedure; |
|
59 | |||
60 | 10 | return $this; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 1 | public function setStorageStack(StorageStack $stack) |
|
67 | { |
||
68 | 1 | $this->stack = $stack; |
|
69 | |||
70 | 1 | return $this; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | 2 | public function setLogger(LoggerInterface $logger) |
|
77 | { |
||
78 | 2 | $this->logger = $logger; |
|
79 | |||
80 | 2 | return $this; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 10 | public function process() |
|
87 | { |
||
88 | 10 | $this->handleProcedures($this->procedures); |
|
89 | 8 | } |
|
90 | |||
91 | /** |
||
92 | * Handles procedure. |
||
93 | * |
||
94 | * @param Procedure $procedure Procedure to handle |
||
95 | */ |
||
96 | abstract protected function handleProcedure(Procedure $procedure); |
||
97 | |||
98 | /** |
||
99 | * Calls procedure handle. |
||
100 | * |
||
101 | * @param Procedure $procedure Procedure to handle |
||
102 | */ |
||
103 | 10 | protected function handleProcedureOuter(Procedure $procedure) |
|
107 | |||
108 | /** |
||
109 | * Handles procedures. |
||
110 | * |
||
111 | * @param array $procedures Procedures to handle |
||
112 | */ |
||
113 | 10 | protected function handleProcedures(array $procedures) |
|
124 | |||
125 | /** |
||
126 | * Handles source. |
||
127 | * |
||
128 | * @param SourceAdapterInterface $adapter Source adapter |
||
129 | * @param Request $request Request to handle |
||
130 | * |
||
131 | * @throws MissingResponseException |
||
132 | * |
||
133 | * @return Response Source adapter response |
||
134 | */ |
||
135 | 8 | protected function handleSource(SourceAdapterInterface $adapter, Request $request) |
|
147 | |||
148 | /** |
||
149 | * Handles sources. |
||
150 | * |
||
151 | * @param array $sources Sources |
||
152 | * |
||
153 | * @return \Iterator Iterator for all source response objects |
||
154 | */ |
||
155 | 1 | protected function handleSources(array $sources) |
|
173 | |||
174 | /** |
||
175 | * Handles worker. |
||
176 | * |
||
177 | * @param WorkerInterface $worker Worker |
||
178 | * @param mixed $object Object to handle |
||
179 | * @param StorageInterface $storage Associated storage |
||
180 | */ |
||
181 | 6 | protected function handleWorker(WorkerInterface $worker, $object, StorageInterface $storage) |
|
196 | |||
197 | /** |
||
198 | * Handles workers. |
||
199 | * |
||
200 | * @param array $workers Workers |
||
201 | * @param StorageInterface $storage Associated storage |
||
202 | */ |
||
203 | 7 | protected function handleWorkers(array $workers, StorageInterface $storage) |
|
211 | |||
212 | /** |
||
213 | * Handles target. |
||
214 | * |
||
215 | * @param TargetAdapterInterface $adapter Target adapter |
||
216 | * @param Request $request Request to handle |
||
217 | * |
||
218 | * @throws MissingResponseException |
||
219 | * |
||
220 | * @return Response Target adapter response |
||
221 | */ |
||
222 | 6 | protected function handleTarget(TargetAdapterInterface $adapter, Request $request) |
|
234 | |||
235 | /** |
||
236 | * Handles targets. |
||
237 | * |
||
238 | * @param array $targets Targets |
||
239 | * @param Request $request Request to handle |
||
240 | * |
||
241 | * @return array Target responses |
||
242 | */ |
||
243 | 7 | protected function handleTargets(array $targets, Request $request) |
|
253 | |||
254 | /** |
||
255 | * Returns next object for an iterator. |
||
256 | * |
||
257 | * @param \Iterator $iterator Iterator to return the next object for |
||
258 | * |
||
259 | * @return mixed|false Object or false, if no object can be returned |
||
260 | */ |
||
261 | 7 | protected function nextObject(\Iterator $iterator) |
|
273 | |||
274 | /** |
||
275 | * Creates scoped storage. |
||
276 | * |
||
277 | * @param string $scope Scope name |
||
278 | * |
||
279 | * @return InMemoryStorage Local storage |
||
280 | */ |
||
281 | 7 | protected function createStorage($scope) |
|
289 | |||
290 | /** |
||
291 | * Injects dependencies. |
||
292 | * |
||
293 | * @param object $component Component |
||
294 | */ |
||
295 | 8 | protected function injectDependencies($component) |
|
305 | |||
306 | /** |
||
307 | * Prepares local storage. |
||
308 | * |
||
309 | * @param mixed $object Initial object |
||
310 | * |
||
311 | * @return InMemoryStorage Local storage |
||
312 | */ |
||
313 | 7 | protected function prepareLocalStorage($object) |
|
320 | |||
321 | /** |
||
322 | * Merges local storage with global storage. |
||
323 | * |
||
324 | * @param StorageInterface $storage Local storage |
||
325 | */ |
||
326 | 6 | protected function mergeStorage(StorageInterface $storage) |
|
332 | } |
||
333 |