bundles/SaintElmos/BaseBundle/Services/Configuration.php line 132

Open in your IDE?
  1. <?php
  2. namespace SaintElmos\BaseBundle\Services;
  3. use Psr\Log\LoggerInterface;
  4. class Configuration
  5. {
  6.     /**  Speicherplatz für überladene Daten.  */
  7.     private $data = array();
  8.     private $logger;
  9.     public function __construct(LoggerInterface $logger)
  10.     {
  11.         $this->logger $logger;
  12.     }
  13.     public function __get($name)
  14.     {
  15.         $this->logger->debug('SETConf::__get('.$name.')');
  16.         return $this->get($name);
  17.     }
  18.     public function get($name)
  19.     {
  20.         $this->logger->debug('SETConf::__get('.$name.')');
  21.         if(strpos($name'__') !== false) {
  22.             list($area,$name) = explode('__'$name2);
  23.         } else {
  24.             $area 'default';
  25.         }
  26.         switch($area) {
  27.             case 'system':
  28.                 $this->loadArea($area);
  29.                 return $this->data['system']->get($name);
  30.                 break;
  31.             case 'website':
  32.                 $this->loadArea($area);
  33.                 return $this->data['website']->get($name);
  34.                 break;
  35.             default:
  36.                 $this->loadArea($area);
  37.                 return !empty($this->data['default'][$name]) ? $this->data['default'][$name] : null;
  38.                 break;
  39.         }
  40.     }
  41.     public function __set($name$value)
  42.     {
  43.         $this->logger->debug('SETConf::__set('.$name.')');
  44.         $this->loadArea('default');
  45.         $this->data['default'][$name] = $value;
  46.         \Pimcore\Cache\Runtime::set('set_config_globals'$this->data['default']);
  47.     }
  48.     public function __isset($name)
  49.     {
  50.         $this->logger->debug('SETConf::__isset('.$name.')');
  51.         if(strpos($name'__') !== false) {
  52.             list($area,$name) = explode('__'$name2);
  53.         } else {
  54.             $area 'default';
  55.         }
  56.         switch($area) {
  57.             case 'system':
  58.                 $this->loadArea($area);
  59.                 return isset($this->data['system']->$name);
  60.                 break;
  61.             case 'website':
  62.                 $this->loadArea($area);
  63.                 return isset($this->data['website']->$name);
  64.                 break;
  65.             default:
  66.                 $this->loadArea('default');
  67.                 return isset($this->data['default'][$name]);
  68.                 break;
  69.         }
  70.     }
  71.     public function getData()
  72.     {
  73.         $this->loadArea('system');
  74.         $this->loadArea('website');
  75.         $this->loadArea('default');
  76.         return $this->data;
  77.     }
  78.     private function loadArea($area)
  79.     {
  80.         switch($area) {
  81.             case 'system':
  82.                 if(empty($this->data['system'])) {
  83.                     if (\Pimcore\Cache\Runtime::isRegistered('pimcore_config_system')) {
  84.                         $this->data['system'] = \Pimcore\Cache\Runtime::get('pimcore_config_system');
  85.                     } else {
  86.                         $this->data['system'] = \Pimcore\Config::getSystemConfig();
  87.                     }
  88.                 }
  89.                 break;
  90.             case 'website':
  91.                 if(empty($this->data['website'])) {
  92.                     if (\Pimcore\Cache\Runtime::isRegistered('pimcore_config_website')) {
  93.                         $this->data['website'] = \Pimcore\Cache\Runtime::get('pimcore_config_website');
  94.                     } else {
  95.                         $this->data['website'] = \Pimcore\Config::getWebsiteConfig();
  96.                     }
  97.                 }
  98.                 break;
  99.             default:
  100.                 if(empty($this->data['default'])) {
  101.                     if (\Pimcore\Cache\Runtime::isRegistered('set_config_globals')) {
  102.                         $this->data['default'] = \Pimcore\Cache\Runtime::get('set_config_globals');
  103.                     } else {
  104.                         \Pimcore\Cache\Runtime::set('set_config_globals', array());
  105.                         $this->data['default'] = array();
  106.                     }
  107.                 }
  108.                 break;
  109.         }
  110.     }
  111. }