defender-security
/
vendor
/
php-di
/
php-di
/
src
/
DI
/
Definition
/
Helper
/
EnvironmentVariableDefinitionHelper.php
EnvironmentVariableDefinitionHelper.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/php-di/php-di/src/DI/Definition/Helper/EnvironmentVariableDefinitionHelper.php
| 1 | <?php |
| 2 | |
| 3 | namespace DI\Definition\Helper; |
| 4 | |
| 5 | use DI\Definition\EnvironmentVariableDefinition; |
| 6 | |
| 7 | /** |
| 8 | * Helps defining how to create an instance of an environment variable definition. |
| 9 | * |
| 10 | * @author James Harris <[email protected]> |
| 11 | */ |
| 12 | class EnvironmentVariableDefinitionHelper implements DefinitionHelper |
| 13 | { |
| 14 | /** |
| 15 | * The name of the environment variable. |
| 16 | * @var string |
| 17 | */ |
| 18 | private $variableName; |
| 19 | |
| 20 | /** |
| 21 | * Whether or not the environment variable definition is optional. |
| 22 | * |
| 23 | * If true and the environment variable given by $variableName has not been |
| 24 | * defined, $defaultValue is used. |
| 25 | * |
| 26 | * @var bool |
| 27 | */ |
| 28 | private $isOptional; |
| 29 | |
| 30 | /** |
| 31 | * The default value to use if the environment variable is optional and not provided. |
| 32 | * @var mixed |
| 33 | */ |
| 34 | private $defaultValue; |
| 35 | |
| 36 | /** |
| 37 | * @param string $variableName The name of the environment variable |
| 38 | * @param bool $isOptional Whether or not the environment variable definition is optional |
| 39 | * @param mixed $defaultValue The default value to use if the environment variable is optional and not provided |
| 40 | */ |
| 41 | public function __construct($variableName, $isOptional, $defaultValue = null) |
| 42 | { |
| 43 | $this->variableName = $variableName; |
| 44 | $this->isOptional = $isOptional; |
| 45 | $this->defaultValue = $defaultValue; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @param string $entryName Container entry name |
| 50 | * |
| 51 | * @return EnvironmentVariableDefinition |
| 52 | */ |
| 53 | public function getDefinition($entryName) |
| 54 | { |
| 55 | return new EnvironmentVariableDefinition($entryName, $this->variableName, $this->isOptional, $this->defaultValue); |
| 56 | } |
| 57 | } |
| 58 |