<?php
namespace SaintElmos\BaseBundle\Services;
use Psr\Log\LoggerInterface;
class Configuration
{
/** Speicherplatz für überladene Daten. */
private $data = array();
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function __get($name)
{
$this->logger->debug('SETConf::__get('.$name.')');
return $this->get($name);
}
public function get($name)
{
$this->logger->debug('SETConf::__get('.$name.')');
if(strpos($name, '__') !== false) {
list($area,$name) = explode('__', $name, 2);
} else {
$area = 'default';
}
switch($area) {
case 'system':
$this->loadArea($area);
return $this->data['system']->get($name);
break;
case 'website':
$this->loadArea($area);
return $this->data['website']->get($name);
break;
default:
$this->loadArea($area);
return !empty($this->data['default'][$name]) ? $this->data['default'][$name] : null;
break;
}
}
public function __set($name, $value)
{
$this->logger->debug('SETConf::__set('.$name.')');
$this->loadArea('default');
$this->data['default'][$name] = $value;
\Pimcore\Cache\Runtime::set('set_config_globals', $this->data['default']);
}
public function __isset($name)
{
$this->logger->debug('SETConf::__isset('.$name.')');
if(strpos($name, '__') !== false) {
list($area,$name) = explode('__', $name, 2);
} else {
$area = 'default';
}
switch($area) {
case 'system':
$this->loadArea($area);
return isset($this->data['system']->$name);
break;
case 'website':
$this->loadArea($area);
return isset($this->data['website']->$name);
break;
default:
$this->loadArea('default');
return isset($this->data['default'][$name]);
break;
}
}
public function getData()
{
$this->loadArea('system');
$this->loadArea('website');
$this->loadArea('default');
return $this->data;
}
private function loadArea($area)
{
switch($area) {
case 'system':
if(empty($this->data['system'])) {
if (\Pimcore\Cache\Runtime::isRegistered('pimcore_config_system')) {
$this->data['system'] = \Pimcore\Cache\Runtime::get('pimcore_config_system');
} else {
$this->data['system'] = \Pimcore\Config::getSystemConfig();
}
}
break;
case 'website':
if(empty($this->data['website'])) {
if (\Pimcore\Cache\Runtime::isRegistered('pimcore_config_website')) {
$this->data['website'] = \Pimcore\Cache\Runtime::get('pimcore_config_website');
} else {
$this->data['website'] = \Pimcore\Config::getWebsiteConfig();
}
}
break;
default:
if(empty($this->data['default'])) {
if (\Pimcore\Cache\Runtime::isRegistered('set_config_globals')) {
$this->data['default'] = \Pimcore\Cache\Runtime::get('set_config_globals');
} else {
\Pimcore\Cache\Runtime::set('set_config_globals', array());
$this->data['default'] = array();
}
}
break;
}
}
}