| 1 |
<?php |
| 2 |
// phpcs:ignoreFile -- Bundled third-party (Mozart) dependency; exempt from plugin coding standards. |
| 3 |
|
| 4 |
declare(strict_types=1); |
| 5 |
|
| 6 |
namespace WPDeveloper\BetterDocs\Dependencies\DI\Definition; |
| 7 |
|
| 8 |
use WPDeveloper\BetterDocs\Dependencies\Psr\Container\ContainerInterface; |
| 9 |
|
| 10 |
/** |
| 11 |
* Definition of a value for dependency injection. |
| 12 |
* |
| 13 |
* @author Matthieu Napoli <matthieu@mnapoli.fr> |
| 14 |
*/ |
| 15 |
class ValueDefinition implements Definition, SelfResolvingDefinition |
| 16 |
{ |
| 17 |
/** |
| 18 |
* Entry name. |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
private $name = ''; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
private $value; |
| 27 |
|
| 28 |
/** |
| 29 |
* @param mixed $value |
| 30 |
*/ |
| 31 |
public function __construct($value) |
| 32 |
{ |
| 33 |
$this->value = $value; |
| 34 |
} |
| 35 |
|
| 36 |
public function getName() : string |
| 37 |
{ |
| 38 |
return $this->name; |
| 39 |
} |
| 40 |
|
| 41 |
public function setName(string $name) |
| 42 |
{ |
| 43 |
$this->name = $name; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* @return mixed |
| 48 |
*/ |
| 49 |
public function getValue() |
| 50 |
{ |
| 51 |
return $this->value; |
| 52 |
} |
| 53 |
|
| 54 |
public function resolve(ContainerInterface $container) |
| 55 |
{ |
| 56 |
return $this->getValue(); |
| 57 |
} |
| 58 |
|
| 59 |
public function isResolvable(ContainerInterface $container) : bool |
| 60 |
{ |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
public function replaceNestedDefinitions(callable $replacer) |
| 65 |
{ |
| 66 |
// no nested definitions |
| 67 |
} |
| 68 |
|
| 69 |
public function __toString() |
| 70 |
{ |
| 71 |
return sprintf('Value (%s)', var_export($this->value, true)); |
| 72 |
} |
| 73 |
} |
| 74 |
|