Version 1
[yaffs-website] / vendor / consolidation / annotated-command / src / Hooks / Dispatchers / InteractHookDispatcher.php
diff --git a/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php b/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InteractHookDispatcher.php
new file mode 100644 (file)
index 0000000..6de718d
--- /dev/null
@@ -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);
+        }
+    }
+}