@@ 12-53 (lines=42) @@ | ||
9 | /** |
|
10 | * Call hooks |
|
11 | */ |
|
12 | class ExtracterHookDispatcher extends HookDispatcher implements ExtractOutputInterface |
|
13 | { |
|
14 | /** |
|
15 | * Convert the result object to printable output in |
|
16 | * structured form. |
|
17 | */ |
|
18 | public function extractOutput($result) |
|
19 | { |
|
20 | if ($result instanceof OutputDataInterface) { |
|
21 | return $result->getOutputData(); |
|
22 | } |
|
23 | ||
24 | $extractors = $this->getOutputExtractors(); |
|
25 | foreach ($extractors as $extractor) { |
|
26 | $structuredOutput = $this->callExtractor($extractor, $result); |
|
27 | if (isset($structuredOutput)) { |
|
28 | return $structuredOutput; |
|
29 | } |
|
30 | } |
|
31 | ||
32 | return $result; |
|
33 | } |
|
34 | ||
35 | protected function callExtractor($extractor, $result) |
|
36 | { |
|
37 | if ($extractor instanceof ExtractOutputInterface) { |
|
38 | return $extractor->extractOutput($result); |
|
39 | } |
|
40 | if (is_callable($extractor)) { |
|
41 | return $extractor($result); |
|
42 | } |
|
43 | } |
|
44 | ||
45 | protected function getOutputExtractors() |
|
46 | { |
|
47 | return $this->getHooks( |
|
48 | [ |
|
49 | HookManager::EXTRACT_OUTPUT, |
|
50 | ] |
|
51 | ); |
|
52 | } |
|
53 | } |
|
54 |
@@ 12-57 (lines=46) @@ | ||
9 | /** |
|
10 | * Call hooks |
|
11 | */ |
|
12 | class StatusDeterminerHookDispatcher extends HookDispatcher implements StatusDeterminerInterface |
|
13 | { |
|
14 | /** |
|
15 | * Call all status determiners, and see if any of them |
|
16 | * know how to convert to a status code. |
|
17 | */ |
|
18 | public function determineStatusCode($result) |
|
19 | { |
|
20 | // If the result (post-processing) is an object that |
|
21 | // implements ExitCodeInterface, then we will ask it |
|
22 | // to give us the status code. |
|
23 | if ($result instanceof ExitCodeInterface) { |
|
24 | return $result->getExitCode(); |
|
25 | } |
|
26 | ||
27 | // If the result does not implement ExitCodeInterface, |
|
28 | // then we'll see if there is a determiner that can |
|
29 | // extract a status code from the result. |
|
30 | $determiners = $this->getStatusDeterminers(); |
|
31 | foreach ($determiners as $determiner) { |
|
32 | $status = $this->callDeterminer($determiner, $result); |
|
33 | if (isset($status)) { |
|
34 | return $status; |
|
35 | } |
|
36 | } |
|
37 | } |
|
38 | ||
39 | protected function callDeterminer($determiner, $result) |
|
40 | { |
|
41 | if ($determiner instanceof StatusDeterminerInterface) { |
|
42 | return $determiner->determineStatusCode($result); |
|
43 | } |
|
44 | if (is_callable($determiner)) { |
|
45 | return $determiner($result); |
|
46 | } |
|
47 | } |
|
48 | ||
49 | protected function getStatusDeterminers() |
|
50 | { |
|
51 | return $this->getHooks( |
|
52 | [ |
|
53 | HookManager::STATUS_DETERMINER, |
|
54 | ] |
|
55 | ); |
|
56 | } |
|
57 | } |
|
58 |