vendor/chamilo/settings-bundle/src/Bundle/Model/Settings.php line 19

  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Sylius\Bundle\SettingsBundle\Model;
  11. use Sylius\Bundle\SettingsBundle\Exception\ParameterNotFoundException;
  12. /**
  13.  * @author Steffen Brem <steffenbrem@gmail.com>
  14.  */
  15. class Settings implements SettingsInterface
  16. {
  17.     /**
  18.      * @var mixed
  19.      */
  20.     protected $id;
  21.     /**
  22.      * @var string
  23.      */
  24.     protected $schemaAlias;
  25.     /**
  26.      * @var string
  27.      */
  28.     protected $namespace;
  29.     /**
  30.      * @var array
  31.      */
  32.     protected $parameters = [];
  33.     public function getId()
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getSchemaAlias(): string
  38.     {
  39.         return $this->schemaAlias;
  40.     }
  41.     public function setSchemaAlias(string $schemaAlias): void
  42.     {
  43.         if (null !== $this->schemaAlias) {
  44.             throw new \LogicException('The schema alias of the settings model is immutable, instantiate a new object in order to use another schema.');
  45.         }
  46.         $this->schemaAlias $schemaAlias;
  47.     }
  48.     public function getNamespace(): string
  49.     {
  50.         return $this->namespace;
  51.     }
  52.     public function setNamespace($namespace): void
  53.     {
  54.         if (null !== $this->namespace) {
  55.             throw new \LogicException('The namespace of the settings model is immutable, instantiate a new object in order to use another namespace.');
  56.         }
  57.         $this->namespace $namespace;
  58.     }
  59.     public function getParameters(): array
  60.     {
  61.         return $this->parameters;
  62.     }
  63.     public function setParameters(array $parameters): void
  64.     {
  65.         $this->parameters $parameters;
  66.     }
  67.     public function offsetExists(mixed $offset): bool
  68.     {
  69.         return $this->has($offset);
  70.     }
  71.     public function offsetGet(mixed $offset): mixed
  72.     {
  73.         return $this->get($offset);
  74.     }
  75.     public function offsetSet(mixed $offsetmixed $value): void
  76.     {
  77.         $this->set($offset$value);
  78.     }
  79.     public function offsetUnset(mixed $offset): void
  80.     {
  81.         $this->remove($offset);
  82.     }
  83.     public function count(): int
  84.     {
  85.         return count($this->parameters);
  86.     }
  87.     public function get(string $name): mixed
  88.     {
  89.         if (!$this->has($name)) {
  90.             throw new ParameterNotFoundException($name);
  91.         }
  92.         return $this->parameters[$name];
  93.     }
  94.     public function has(string $name): bool
  95.     {
  96.         return array_key_exists($name$this->parameters);
  97.     }
  98.     public function set(string $namemixed $value): void
  99.     {
  100.         $this->parameters[$name] = $value;
  101.     }
  102.     public function remove(string $name): void
  103.     {
  104.         if (!$this->has($name)) {
  105.             throw new ParameterNotFoundException($name);
  106.         }
  107.         unset($this->parameters[$name]);
  108.     }
  109. }