vendor/friendsofsymfony/ckeditor-bundle/src/Model/ConfigManager.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSCKEditor Bundle.
  4.  *
  5.  * (c) 2018 - present  Friends of Symfony
  6.  * (c) 2009 - 2017     Eric GELOEN <geloen.eric@gmail.com>
  7.  *
  8.  * For the full copyright and license information, please read the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace FOS\CKEditorBundle\Model;
  12. use FOS\CKEditorBundle\Exception\ConfigManagerException;
  13. @trigger_error(
  14.     'The '.__NAMESPACE__.'ConfigManager is deprecated since 1.x '.
  15.     'and will be removed with the 2.0 release.',
  16.     E_USER_DEPRECATED
  17. );
  18. /**
  19.  * @author GeLo <geloen.eric@gmail.com>
  20.  */
  21. class ConfigManager implements ConfigManagerInterface
  22. {
  23.     /**
  24.      * @var string
  25.      */
  26.     private $defaultConfig;
  27.     /**
  28.      * @var array
  29.      */
  30.     private $configs = [];
  31.     /**
  32.      * @param array       $configs
  33.      * @param string|null $defaultConfig
  34.      */
  35.     public function __construct(array $configs = [], $defaultConfig null)
  36.     {
  37.         $this->setConfigs($configs);
  38.         if (null !== $defaultConfig) {
  39.             $this->setDefaultConfig($defaultConfig);
  40.         }
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function getDefaultConfig()
  46.     {
  47.         return $this->defaultConfig;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function setDefaultConfig($defaultConfig)
  53.     {
  54.         if (!$this->hasConfig($defaultConfig)) {
  55.             throw ConfigManagerException::configDoesNotExist($defaultConfig);
  56.         }
  57.         $this->defaultConfig $defaultConfig;
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function hasConfigs()
  63.     {
  64.         return !empty($this->configs);
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function getConfigs()
  70.     {
  71.         return $this->configs;
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function setConfigs(array $configs)
  77.     {
  78.         foreach ($configs as $name => $config) {
  79.             $this->setConfig($name$config);
  80.         }
  81.     }
  82.     /**
  83.      * {@inheritdoc}
  84.      */
  85.     public function hasConfig($name)
  86.     {
  87.         return isset($this->configs[$name]);
  88.     }
  89.     /**
  90.      * {@inheritdoc}
  91.      */
  92.     public function getConfig($name)
  93.     {
  94.         if (!$this->hasConfig($name)) {
  95.             throw ConfigManagerException::configDoesNotExist($name);
  96.         }
  97.         return $this->configs[$name];
  98.     }
  99.     /**
  100.      * {@inheritdoc}
  101.      */
  102.     public function setConfig($name, array $config)
  103.     {
  104.         $this->configs[$name] = $config;
  105.     }
  106.     /**
  107.      * {@inheritdoc}
  108.      */
  109.     public function mergeConfig($name, array $config)
  110.     {
  111.         $this->configs[$name] = array_merge($this->getConfig($name), $config);
  112.     }
  113. }