Mercurial > hg > isophonics-drupal-site
diff vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,41 @@ +<?php + +namespace Consolidation\AnnotatedCommand\Hooks\Dispatchers; + +use Consolidation\AnnotatedCommand\AnnotationData; +use Consolidation\AnnotatedCommand\Hooks\HookManager; +use Consolidation\AnnotatedCommand\Hooks\InteractorInterface; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Call hooks + */ +class InteractHookDispatcher extends HookDispatcher +{ + public function interact( + InputInterface $input, + OutputInterface $output, + AnnotationData $annotationData + ) { + $hooks = [ + HookManager::PRE_INTERACT, + HookManager::INTERACT, + HookManager::POST_INTERACT + ]; + $interactors = $this->getHooks($hooks, $annotationData); + foreach ($interactors as $interactor) { + $this->callInteractor($interactor, $input, $output, $annotationData); + } + } + + protected function callInteractor($interactor, $input, $output, AnnotationData $annotationData) + { + if ($interactor instanceof InteractorInterface) { + return $interactor->interact($input, $output, $annotationData); + } + if (is_callable($interactor)) { + return $interactor($input, $output, $annotationData); + } + } +}