| @@ 12-47 (lines=36) @@ | ||
| 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 | $hooks = [ |
|
| 25 | HookManager::EXTRACT_OUTPUT, |
|
| 26 | ]; |
|
| 27 | $extractors = $this->getHooks($hooks); |
|
| 28 | foreach ($extractors as $extractor) { |
|
| 29 | $structuredOutput = $this->callExtractor($extractor, $result); |
|
| 30 | if (isset($structuredOutput)) { |
|
| 31 | return $structuredOutput; |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| 35 | return $result; |
|
| 36 | } |
|
| 37 | ||
| 38 | protected function callExtractor($extractor, $result) |
|
| 39 | { |
|
| 40 | if ($extractor instanceof ExtractOutputInterface) { |
|
| 41 | return $extractor->extractOutput($result); |
|
| 42 | } |
|
| 43 | if (is_callable($extractor)) { |
|
| 44 | return $extractor($result); |
|
| 45 | } |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 12-51 (lines=40) @@ | ||
| 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 | $hooks = [ |
|
| 28 | HookManager::STATUS_DETERMINER, |
|
| 29 | ]; |
|
| 30 | // If the result does not implement ExitCodeInterface, |
|
| 31 | // then we'll see if there is a determiner that can |
|
| 32 | // extract a status code from the result. |
|
| 33 | $determiners = $this->getHooks($hooks); |
|
| 34 | foreach ($determiners as $determiner) { |
|
| 35 | $status = $this->callDeterminer($determiner, $result); |
|
| 36 | if (isset($status)) { |
|
| 37 | return $status; |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| 42 | protected function callDeterminer($determiner, $result) |
|
| 43 | { |
|
| 44 | if ($determiner instanceof StatusDeterminerInterface) { |
|
| 45 | return $determiner->determineStatusCode($result); |
|
| 46 | } |
|
| 47 | if (is_callable($determiner)) { |
|
| 48 | return $determiner($result); |
|
| 49 | } |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||