| @@ 14-40 (lines=27) @@ | ||
| 11 | /** |
|
| 12 | * Call hooks |
|
| 13 | */ |
|
| 14 | class InitializeHookDispatcher extends HookDispatcher implements InitializeHookInterface |
|
| 15 | { |
|
| 16 | public function initialize( |
|
| 17 | InputInterface $input, |
|
| 18 | AnnotationData $annotationData |
|
| 19 | ) { |
|
| 20 | $hooks = [ |
|
| 21 | HookManager::PRE_INITIALIZE, |
|
| 22 | HookManager::INITIALIZE, |
|
| 23 | HookManager::POST_INITIALIZE |
|
| 24 | ]; |
|
| 25 | $providers = $this->getHooks($hooks, $annotationData); |
|
| 26 | foreach ($providers as $provider) { |
|
| 27 | $this->callInitializeHook($provider, $input, $annotationData); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| 31 | protected function callInitializeHook($provider, $input, AnnotationData $annotationData) |
|
| 32 | { |
|
| 33 | if ($provider instanceof InitializeHookInterface) { |
|
| 34 | return $provider->initialize($input, $annotationData); |
|
| 35 | } |
|
| 36 | if (is_callable($provider)) { |
|
| 37 | return $provider($input, $annotationData); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 14-41 (lines=28) @@ | ||
| 11 | /** |
|
| 12 | * Call hooks |
|
| 13 | */ |
|
| 14 | class InteractHookDispatcher extends HookDispatcher |
|
| 15 | { |
|
| 16 | public function interact( |
|
| 17 | InputInterface $input, |
|
| 18 | OutputInterface $output, |
|
| 19 | AnnotationData $annotationData |
|
| 20 | ) { |
|
| 21 | $hooks = [ |
|
| 22 | HookManager::PRE_INTERACT, |
|
| 23 | HookManager::INTERACT, |
|
| 24 | HookManager::POST_INTERACT |
|
| 25 | ]; |
|
| 26 | $interactors = $this->getHooks($hooks, $annotationData); |
|
| 27 | foreach ($interactors as $interactor) { |
|
| 28 | $this->callInteractor($interactor, $input, $output, $annotationData); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | protected function callInteractor($interactor, $input, $output, AnnotationData $annotationData) |
|
| 33 | { |
|
| 34 | if ($interactor instanceof InteractorInterface) { |
|
| 35 | return $interactor->interact($input, $output, $annotationData); |
|
| 36 | } |
|
| 37 | if (is_callable($interactor)) { |
|
| 38 | return $interactor($input, $output, $annotationData); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||