Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / league / container / src / Definition / ClassDefinition.php
1 <?php
2
3 namespace League\Container\Definition;
4
5 use ReflectionClass;
6
7 class ClassDefinition extends AbstractDefinition implements ClassDefinitionInterface
8 {
9     /**
10      * @var array
11      */
12     protected $methods = [];
13
14     /**
15      * {@inheritdoc}
16      */
17     public function withMethodCall($method, array $args = [])
18     {
19         $this->methods[] = [
20             'method'    => $method,
21             'arguments' => $args
22         ];
23
24         return $this;
25     }
26
27     /**
28      * {@inheritdoc}
29      */
30     public function withMethodCalls(array $methods = [])
31     {
32         foreach ($methods as $method => $args) {
33             $this->withMethodCall($method, $args);
34         }
35
36         return $this;
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     public function build(array $args = [])
43     {
44         $args       = (empty($args)) ? $this->arguments : $args;
45         $resolved   = $this->resolveArguments($args);
46         $reflection = new ReflectionClass($this->concrete);
47         $instance   = $reflection->newInstanceArgs($resolved);
48
49         return $this->invokeMethods($instance);
50     }
51
52     /**
53      * Invoke methods on resolved instance.
54      *
55      * @param  object $instance
56      * @return object
57      */
58     protected function invokeMethods($instance)
59     {
60         foreach ($this->methods as $method) {
61             $args = $this->resolveArguments($method['arguments']);
62             call_user_func_array([$instance, $method['method']], $args);
63         }
64
65         return $instance;
66     }
67 }