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\Helper;
12 use DI\Definition\EnvironmentVariableDefinition;
15 * Helps defining how to create an instance of an environment variable definition.
17 * @author James Harris <james.harris@icecave.com.au>
19 class EnvironmentVariableDefinitionHelper implements DefinitionHelper
22 * The name of the environment variable
25 private $variableName;
28 * Whether or not the environment variable definition is optional
30 * If true and the environment variable given by $variableName has not been
31 * defined, $defaultValue is used.
38 * The default value to use if the environment variable is optional and not provided
41 private $defaultValue;
44 * @param string $variableName The name of the environment variable
45 * @param boolean $isOptional Whether or not the environment variable definition is optional
46 * @param mixed $defaultValue The default value to use if the environment variable is optional and not provided
48 public function __construct($variableName, $isOptional, $defaultValue = null)
50 $this->variableName = $variableName;
51 $this->isOptional = $isOptional;
52 $this->defaultValue = $defaultValue;
56 * @param string $entryName Container entry name
58 * @return EnvironmentVariableDefinition
60 public function getDefinition($entryName)
62 return new EnvironmentVariableDefinition($entryName, $this->variableName, $this->isOptional, $this->defaultValue);