elementor
/
vendor_prefixed
/
dependency-injection
/
php-di
/
php-di
/
src
/
Definition
/
Reference.php
Reference.php in Elementor Website Builder – more than just a page builder 3.28.0-beta1, at vendor_prefixed/dependency-injection/php-di/php-di/src/Definition/Reference.php
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace ElementorDeps\DI\Definition; |
| 5 | |
| 6 | use ElementorDeps\Psr\Container\ContainerInterface; |
| 7 | /** |
| 8 | * Represents a reference to another entry. |
| 9 | * |
| 10 | * @author Matthieu Napoli <[email protected]> |
| 11 | */ |
| 12 | class Reference implements Definition, SelfResolvingDefinition |
| 13 | { |
| 14 | /** |
| 15 | * Entry name. |
| 16 | * @var string |
| 17 | */ |
| 18 | private $name = ''; |
| 19 | /** |
| 20 | * Name of the target entry. |
| 21 | * @var string |
| 22 | */ |
| 23 | private $targetEntryName; |
| 24 | /** |
| 25 | * @param string $targetEntryName Name of the target entry |
| 26 | */ |
| 27 | public function __construct(string $targetEntryName) |
| 28 | { |
| 29 | $this->targetEntryName = $targetEntryName; |
| 30 | } |
| 31 | public function getName() : string |
| 32 | { |
| 33 | return $this->name; |
| 34 | } |
| 35 | public function setName(string $name) |
| 36 | { |
| 37 | $this->name = $name; |
| 38 | } |
| 39 | public function getTargetEntryName() : string |
| 40 | { |
| 41 | return $this->targetEntryName; |
| 42 | } |
| 43 | public function resolve(ContainerInterface $container) |
| 44 | { |
| 45 | return $container->get($this->getTargetEntryName()); |
| 46 | } |
| 47 | public function isResolvable(ContainerInterface $container) : bool |
| 48 | { |
| 49 | return $container->has($this->getTargetEntryName()); |
| 50 | } |
| 51 | public function replaceNestedDefinitions(callable $replacer) |
| 52 | { |
| 53 | // no nested definitions |
| 54 | } |
| 55 | public function __toString() |
| 56 | { |
| 57 | return \sprintf('get(%s)', $this->targetEntryName); |
| 58 | } |
| 59 | } |
| 60 |