elementor
/
vendor_prefixed
/
php-di
/
php-di
/
src
/
Definition
/
ObjectDefinition
/
MethodInjection.php
MethodInjection.php in Elementor Website Builder – more than just a page builder 3.27.4, at vendor_prefixed/php-di/php-di/src/Definition/ObjectDefinition/MethodInjection.php
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace ElementorDeps\DI\Definition\ObjectDefinition; |
| 5 | |
| 6 | use ElementorDeps\DI\Definition\Definition; |
| 7 | /** |
| 8 | * Describe an injection in an object method. |
| 9 | * |
| 10 | * @author Matthieu Napoli <matthieu@mnapoli.fr> |
| 11 | */ |
| 12 | class MethodInjection implements Definition |
| 13 | { |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $methodName; |
| 18 | /** |
| 19 | * @var mixed[] |
| 20 | */ |
| 21 | private $parameters = []; |
| 22 | public function __construct(string $methodName, array $parameters = []) |
| 23 | { |
| 24 | $this->methodName = $methodName; |
| 25 | $this->parameters = $parameters; |
| 26 | } |
| 27 | public static function constructor(array $parameters = []) : self |
| 28 | { |
| 29 | return new self('__construct', $parameters); |
| 30 | } |
| 31 | public function getMethodName() : string |
| 32 | { |
| 33 | return $this->methodName; |
| 34 | } |
| 35 | /** |
| 36 | * @return mixed[] |
| 37 | */ |
| 38 | public function getParameters() : array |
| 39 | { |
| 40 | return $this->parameters; |
| 41 | } |
| 42 | /** |
| 43 | * Replace the parameters of the definition by a new array of parameters. |
| 44 | */ |
| 45 | public function replaceParameters(array $parameters) |
| 46 | { |
| 47 | $this->parameters = $parameters; |
| 48 | } |
| 49 | public function merge(self $definition) |
| 50 | { |
| 51 | // In case of conflicts, the current definition prevails. |
| 52 | $this->parameters = $this->parameters + $definition->parameters; |
| 53 | } |
| 54 | public function getName() : string |
| 55 | { |
| 56 | return ''; |
| 57 | } |
| 58 | public function setName(string $name) |
| 59 | { |
| 60 | // The name does not matter for method injections |
| 61 | } |
| 62 | public function replaceNestedDefinitions(callable $replacer) |
| 63 | { |
| 64 | $this->parameters = \array_map($replacer, $this->parameters); |
| 65 | } |
| 66 | /** |
| 67 | * {@inheritdoc} |
| 68 | */ |
| 69 | public function __toString() |
| 70 | { |
| 71 | return \sprintf('method(%s)', $this->methodName); |
| 72 | } |
| 73 | } |
| 74 |