5 * @link http://php-di.org/
6 * @copyright Matthieu Napoli (http://mnapoli.fr/)
7 * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
10 namespace DI\Definition;
15 * Defines a reference to an environment variable, with fallback to a default
16 * value if the environment variable is not defined.
18 * @author James Harris <james.harris@icecave.com.au>
20 class EnvironmentVariableDefinition implements CacheableDefinition
29 * The name of the environment variable
32 private $variableName;
35 * Whether or not the environment variable definition is optional
37 * If true and the environment variable given by $variableName has not been
38 * defined, $defaultValue is used.
45 * The default value to use if the environment variable is optional and not provided
48 private $defaultValue;
56 * @param string $name Entry name
57 * @param string $variableName The name of the environment variable
58 * @param boolean $isOptional Whether or not the environment variable definition is optional
59 * @param mixed $defaultValue The default value to use if the environment variable is optional and not provided
61 public function __construct($name, $variableName, $isOptional = false, $defaultValue = null)
64 $this->variableName = $variableName;
65 $this->isOptional = $isOptional;
66 $this->defaultValue = $defaultValue;
70 * @return string Entry name
72 public function getName()
78 * @return string The name of the environment variable
80 public function getVariableName()
82 return $this->variableName;
86 * @return boolean Whether or not the environment variable definition is optional
88 public function isOptional()
90 return $this->isOptional;
94 * @return mixed The default value to use if the environment variable is optional and not provided
96 public function getDefaultValue()
98 return $this->defaultValue;
102 * @param string $scope
104 public function setScope($scope)
106 $this->scope = $scope;
112 public function getScope()
114 return $this->scope ?: Scope::SINGLETON;