Example #1
0
 /**
  * Load configuration for current scope
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _loadScopedData()
 {
     $scope = $this->_configScope->getCurrentScope();
     if (false == isset($this->_loadedScopes[$scope])) {
         if (false == in_array($scope, $this->_scopePriorityScheme)) {
             $this->_scopePriorityScheme[] = $scope;
         }
         $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId;
         $data = $this->_cache->load($cacheId);
         if ($data) {
             list($this->_data, $this->_inherited, $this->_processed) = unserialize($data);
             foreach ($this->_scopePriorityScheme as $scope) {
                 $this->_loadedScopes[$scope] = true;
             }
         } else {
             $virtualTypes = array();
             foreach ($this->_scopePriorityScheme as $scopeCode) {
                 if (false == isset($this->_loadedScopes[$scopeCode])) {
                     $data = $this->_reader->read($scopeCode);
                     unset($data['preferences']);
                     if (!count($data)) {
                         continue;
                     }
                     $this->_inherited = array();
                     $this->_processed = array();
                     $this->merge($data);
                     $this->_loadedScopes[$scopeCode] = true;
                     foreach ($data as $class => $config) {
                         if (isset($config['type'])) {
                             $virtualTypes[] = $class;
                         }
                     }
                 }
                 if ($scopeCode == $scope) {
                     break;
                 }
             }
             foreach ($virtualTypes as $class) {
                 $this->_inheritPlugins(ltrim($class, '\\'));
             }
             foreach ($this->_classDefinitions->getClasses() as $class) {
                 $this->_inheritPlugins($class);
             }
             $this->_cache->save(serialize(array($this->_data, $this->_inherited, $this->_processed)), $cacheId);
         }
         $this->_pluginInstances = array();
     }
 }
Example #2
0
 /**
  * Extend configuration
  *
  * @param array $configuration
  * @return void
  */
 public function extend(array $configuration)
 {
     if ($this->_cache) {
         if (!$this->_currentCacheKey) {
             $this->_currentCacheKey = md5(serialize(array($this->_arguments, $this->_nonShared, $this->_preferences, $this->_virtualTypes)));
         }
         $key = md5($this->_currentCacheKey . serialize($configuration));
         $cached = $this->_cache->get($key);
         if ($cached) {
             list($this->_arguments, $this->_nonShared, $this->_preferences, $this->_virtualTypes, $this->_mergedArguments) = $cached;
         } else {
             $this->_mergeConfiguration($configuration);
             if (!$this->_mergedArguments) {
                 foreach ($this->_definitions->getClasses() as $class) {
                     $this->_collectConfiguration($class);
                 }
             }
             $this->_cache->save(array($this->_arguments, $this->_nonShared, $this->_preferences, $this->_virtualTypes, $this->_mergedArguments), $key);
         }
         $this->_currentCacheKey = $key;
     } else {
         $this->_mergeConfiguration($configuration);
     }
 }
Example #3
0
 /**
  * @param \Magento\Framework\Config\ReaderInterface $reader
  * @param \Magento\Framework\Config\ScopeListInterface $scopeList
  * @param \Magento\Framework\Cache\FrontendInterface $cache
  * @param \Magento\Framework\ObjectManager\Relations $relations
  * @param \Magento\Framework\Interception\ObjectManager\Config $omConfig
  * @param \Magento\Framework\ObjectManager\Definition $classDefinitions
  * @param string $cacheId
  */
 public function __construct(\Magento\Framework\Config\ReaderInterface $reader, \Magento\Framework\Config\ScopeListInterface $scopeList, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Framework\ObjectManager\Relations $relations, \Magento\Framework\Interception\ObjectManager\Config $omConfig, \Magento\Framework\ObjectManager\Definition $classDefinitions, $cacheId = 'interception')
 {
     $this->_omConfig = $omConfig;
     $this->_relations = $relations;
     $this->_classDefinitions = $classDefinitions;
     $this->_cache = $cache;
     $this->_cacheId = $cacheId;
     $this->_reader = $reader;
     $intercepted = $this->_cache->load($this->_cacheId);
     if ($intercepted !== false) {
         $this->_intercepted = unserialize($intercepted);
     } else {
         $config = array();
         foreach ($scopeList->getAllScopes() as $scope) {
             $config = array_replace_recursive($config, $this->_reader->read($scope));
         }
         unset($config['preferences']);
         foreach ($config as $typeName => $typeConfig) {
             if (!empty($typeConfig['plugins'])) {
                 $this->_intercepted[ltrim($typeName, '\\')] = true;
             }
         }
         foreach ($config as $typeName => $typeConfig) {
             $this->hasPlugins(ltrim($typeName, '\\'));
         }
         foreach ($classDefinitions->getClasses() as $class) {
             $this->hasPlugins($class);
         }
         $this->_cache->save(serialize($this->_intercepted), $this->_cacheId);
     }
 }