<?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;
    }
}