Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / TaskAccessor.php
1 <?php
2 namespace Robo;
3
4 use Robo\Common\BuilderAwareTrait;
5
6 trait TaskAccessor
7 {
8     use BuilderAwareTrait;
9
10     /**
11      * Provides the collection builder with access to all of the
12      * protected 'task' methods available on this object.
13      *
14      * @param string $fn
15      * @param array $args
16      *
17      * @return null|\Robo\Collection\CollectionBuilder
18      */
19     public function getBuiltTask($fn, $args)
20     {
21         if (preg_match('#^task[A-Z]#', $fn)) {
22             return call_user_func_array([$this, $fn], $args);
23         }
24     }
25
26     /**
27      * Alternative access to instantiate. Use:
28      *
29      *   $this->task(Foo::class, $a, $b);
30      *
31      * instead of:
32      *
33      *   $this->taskFoo($a, $b);
34      *
35      * The later form is preferred.
36      *
37      * @return \Robo\Collection\CollectionBuilder
38      */
39     protected function task()
40     {
41         $args = func_get_args();
42         $name = array_shift($args);
43
44         $collectionBuilder = $this->collectionBuilder();
45         return $collectionBuilder->build($name, $args);
46     }
47 }