Mercurial > hg > isophonics-drupal-site
comparison vendor/consolidation/annotated-command/src/Hooks/Dispatchers/ExtracterHookDispatcher.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers; | |
4 | |
5 use Consolidation\AnnotatedCommand\Hooks\ExtractOutputInterface; | |
6 use Consolidation\AnnotatedCommand\Hooks\HookManager; | |
7 use Consolidation\AnnotatedCommand\OutputDataInterface; | |
8 | |
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 } |