5861641fdb2e0d8ef6c10f86a5fc1dbd63737772
[GitHub/WoltLab/WCF.git] /
1 <?php
2 /**
3 * PHP-DI
4 *
5 * @link http://php-di.org/
6 * @copyright Matthieu Napoli (http://mnapoli.fr/)
7 * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
8 */
9
10 namespace DI\Definition\ObjectDefinition;
11
12 use DI\Definition\Definition;
13 use DI\Scope;
14
15 /**
16 * Describe an injection in an object method.
17 *
18 * @author Matthieu Napoli <matthieu@mnapoli.fr>
19 */
20 class MethodInjection implements Definition
21 {
22 /**
23 * @var string
24 */
25 private $methodName;
26
27 /**
28 * @var array
29 */
30 private $parameters = [];
31
32 /**
33 * @param string $methodName
34 * @param array $parameters
35 */
36 public function __construct($methodName, array $parameters = [])
37 {
38 $this->methodName = (string) $methodName;
39 $this->parameters = $parameters;
40 }
41
42 public static function constructor(array $parameters = [])
43 {
44 return new self('__construct', $parameters);
45 }
46
47 /**
48 * @return string Method name
49 */
50 public function getMethodName()
51 {
52 return $this->methodName;
53 }
54
55 /**
56 * @return array
57 */
58 public function getParameters()
59 {
60 return $this->parameters;
61 }
62
63 /**
64 * Replace the parameters of the definition by a new array of parameters.
65 *
66 * @param array $parameters
67 */
68 public function replaceParameters(array $parameters)
69 {
70 $this->parameters = $parameters;
71 }
72
73 public function merge(MethodInjection $definition)
74 {
75 // In case of conflicts, the current definition prevails.
76 $this->parameters = $this->parameters + $definition->parameters;
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function getName()
83 {
84 return null;
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function getScope()
91 {
92 return Scope::PROTOTYPE;
93 }
94 }