Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Collection / CollectionProcessHook.php
1 <?php
2 namespace Robo\Collection;
3
4 use Consolidation\AnnotatedCommand\Hooks\ProcessResultInterface;
5 use Consolidation\AnnotatedCommand\CommandData;
6 use Robo\Contract\TaskInterface;
7 use Robo\Result;
8
9 /**
10  * The collection process hook is added to the annotation command
11  * hook manager in Runner::configureContainer(). This hook will be
12  * called every time a command runs.  If the command result is a
13  * \Robo\Contract\TaskInterface (in particular, \Robo\Collection\Collection),
14  * then we run the collection, and return the result.  We ignore results
15  * of any other type.
16  */
17 class CollectionProcessHook implements ProcessResultInterface
18 {
19     /**
20      * @param \Robo\Result|\Robo\Contract\TaskInterface $result
21      * @param \Consolidation\AnnotatedCommand\CommandData $commandData
22      *
23      * @return null|\Robo\Result
24      */
25     public function process($result, CommandData $commandData)
26     {
27         if ($result instanceof TaskInterface) {
28             try {
29                 return $result->run();
30             } catch (\Exception $e) {
31                 return Result::fromException($result, $e);
32             }
33         }
34     }
35 }