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)
10 namespace DI\Definition\ObjectDefinition;
12 use DI\Definition\Definition;
16 * Describe an injection in an object method.
18 * @author Matthieu Napoli <matthieu@mnapoli.fr>
20 class MethodInjection implements Definition
30 private $parameters = [];
33 * @param string $methodName
34 * @param array $parameters
36 public function __construct($methodName, array $parameters = [])
38 $this->methodName = (string) $methodName;
39 $this->parameters = $parameters;
42 public static function constructor(array $parameters = [])
44 return new self('__construct', $parameters);
48 * @return string Method name
50 public function getMethodName()
52 return $this->methodName;
58 public function getParameters()
60 return $this->parameters;
64 * Replace the parameters of the definition by a new array of parameters.
66 * @param array $parameters
68 public function replaceParameters(array $parameters)
70 $this->parameters = $parameters;
73 public function merge(MethodInjection $definition)
75 // In case of conflicts, the current definition prevails.
76 $this->parameters = $this->parameters + $definition->parameters;
82 public function getName()
90 public function getScope()
92 return Scope::PROTOTYPE;