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