| @@ 14-47 (lines=34) @@ | ||
| 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 | $providers = $this->getInitializeHooks($annotationData); |
|
| 21 | foreach ($providers as $provider) { |
|
| 22 | $this->callInitializeHook($provider, $input, $annotationData); |
|
| 23 | } |
|
| 24 | } |
|
| 25 | ||
| 26 | protected function callInitializeHook($provider, $input, AnnotationData $annotationData) |
|
| 27 | { |
|
| 28 | if ($provider instanceof InitializeHookInterface) { |
|
| 29 | return $provider->initialize($input, $annotationData); |
|
| 30 | } |
|
| 31 | if (is_callable($provider)) { |
|
| 32 | return $provider($input, $annotationData); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| 36 | protected function getInitializeHooks(AnnotationData $annotationData) |
|
| 37 | { |
|
| 38 | return $this->getHooks( |
|
| 39 | [ |
|
| 40 | HookManager::PRE_INITIALIZE, |
|
| 41 | HookManager::INITIALIZE, |
|
| 42 | HookManager::POST_INITIALIZE |
|
| 43 | ], |
|
| 44 | $annotationData |
|
| 45 | ); |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 14-48 (lines=35) @@ | ||
| 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 | $interactors = $this->getInteractors($annotationData); |
|
| 22 | foreach ($interactors as $interactor) { |
|
| 23 | $this->callInteractor($interactor, $input, $output, $annotationData); |
|
| 24 | } |
|
| 25 | } |
|
| 26 | ||
| 27 | protected function callInteractor($interactor, $input, $output, AnnotationData $annotationData) |
|
| 28 | { |
|
| 29 | if ($interactor instanceof InteractorInterface) { |
|
| 30 | return $interactor->interact($input, $output, $annotationData); |
|
| 31 | } |
|
| 32 | if (is_callable($interactor)) { |
|
| 33 | return $interactor($input, $output, $annotationData); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| 37 | protected function getInteractors(AnnotationData $annotationData) |
|
| 38 | { |
|
| 39 | return $this->getHooks( |
|
| 40 | [ |
|
| 41 | HookManager::PRE_INTERACT, |
|
| 42 | HookManager::INTERACT, |
|
| 43 | HookManager::POST_INTERACT |
|
| 44 | ], |
|
| 45 | $annotationData |
|
| 46 | ); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||