| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WPMU_DEV\Defender\Vendor\DI\Definition\ObjectDefinition; |
| 6 |
|
| 7 |
/** |
| 8 |
* Describe an injection in a class property. |
| 9 |
* |
| 10 |
* @author Matthieu Napoli <[email protected]> |
| 11 |
*/ |
| 12 |
class PropertyInjection |
| 13 |
{ |
| 14 |
private string $propertyName; |
| 15 |
|
| 16 |
/** |
| 17 |
* Value that should be injected in the property. |
| 18 |
*/ |
| 19 |
private mixed $value; |
| 20 |
|
| 21 |
/** |
| 22 |
* Use for injecting in properties of parent classes: the class name |
| 23 |
* must be the name of the parent class because private properties |
| 24 |
* can be attached to the parent classes, not the one we are resolving. |
| 25 |
*/ |
| 26 |
private ?string $className; |
| 27 |
|
| 28 |
/** |
| 29 |
* @param string $propertyName Property name |
| 30 |
* @param mixed $value Value that should be injected in the property |
| 31 |
*/ |
| 32 |
public function __construct(string $propertyName, mixed $value, ?string $className = null) |
| 33 |
{ |
| 34 |
$this->propertyName = $propertyName; |
| 35 |
$this->value = $value; |
| 36 |
$this->className = $className; |
| 37 |
} |
| 38 |
|
| 39 |
public function getPropertyName() : string |
| 40 |
{ |
| 41 |
return $this->propertyName; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @return mixed Value that should be injected in the property |
| 46 |
*/ |
| 47 |
public function getValue() : mixed |
| 48 |
{ |
| 49 |
return $this->value; |
| 50 |
} |
| 51 |
|
| 52 |
public function getClassName() : ?string |
| 53 |
{ |
| 54 |
return $this->className; |
| 55 |
} |
| 56 |
|
| 57 |
public function replaceNestedDefinition(callable $replacer) : void |
| 58 |
{ |
| 59 |
$this->value = $replacer($this->value); |
| 60 |
} |
| 61 |
} |
| 62 |
|