Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Collection / CollectionProcessHook.php
diff --git a/vendor/consolidation/robo/src/Collection/CollectionProcessHook.php b/vendor/consolidation/robo/src/Collection/CollectionProcessHook.php
new file mode 100644 (file)
index 0000000..91efde7
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace Robo\Collection;
+
+use Consolidation\AnnotatedCommand\Hooks\ProcessResultInterface;
+use Consolidation\AnnotatedCommand\CommandData;
+use Robo\Contract\TaskInterface;
+use Robo\Result;
+
+/**
+ * The collection process hook is added to the annotation command
+ * hook manager in Runner::configureContainer(). This hook will be
+ * called every time a command runs.  If the command result is a
+ * \Robo\Contract\TaskInterface (in particular, \Robo\Collection\Collection),
+ * then we run the collection, and return the result.  We ignore results
+ * of any other type.
+ */
+class CollectionProcessHook implements ProcessResultInterface
+{
+    /**
+     * @param \Robo\Result|\Robo\Contract\TaskInterface $result
+     * @param \Consolidation\AnnotatedCommand\CommandData $commandData
+     *
+     * @return null|\Robo\Result
+     */
+    public function process($result, CommandData $commandData)
+    {
+        if ($result instanceof TaskInterface) {
+            try {
+                return $result->run();
+            } catch (\Exception $e) {
+                return Result::fromException($result, $e);
+            }
+        }
+    }
+}