|
1234567891011121314151617181920212223242526272829303132333435 |
- <?php
-
- namespace common\components;
-
- use yii\base\ErrorException;
-
- class ParameterBag
- {
- protected array $parameters = [];
-
- public function __construct()
- {
- $this->parameters = \Yii::$app->params;
- }
-
- public function get(string $name)
- {
- if(isset($this->parameters[$name])) {
- return $this->parameters[$name];
- }
- else {
- throw new ErrorException('Paramètre '.$name.' non défini.');
- }
- }
-
- public function has(string $name)
- {
- return \array_key_exists($name, $this->parameters);
- }
-
- public function set(string $name, $value)
- {
- $this->parameters[$name] = $value;
- }
- }
|