3 namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers;
5 use Consolidation\AnnotatedCommand\ExitCodeInterface;
6 use Consolidation\AnnotatedCommand\Hooks\HookManager;
7 use Consolidation\AnnotatedCommand\Hooks\StatusDeterminerInterface;
12 class StatusDeterminerHookDispatcher extends HookDispatcher implements StatusDeterminerInterface
15 * Call all status determiners, and see if any of them
16 * know how to convert to a status code.
18 public function determineStatusCode($result)
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();
28 HookManager::STATUS_DETERMINER,
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);
42 protected function callDeterminer($determiner, $result)
44 if ($determiner instanceof StatusDeterminerInterface) {
45 return $determiner->determineStatusCode($result);
47 if (is_callable($determiner)) {
48 return $determiner($result);