コード例 #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();
     }
 }
コード例 #2
0
 /**
  * Create instance with call time arguments
  *
  * @param string $requestedType
  * @param array $arguments
  * @return object
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function create($requestedType, array $arguments = array())
 {
     $type = $this->config->getInstanceType($requestedType);
     $parameters = $this->definitions->getParameters($type);
     if ($parameters == null) {
         return new $type();
     }
     if (isset($this->creationStack[$requestedType])) {
         $lastFound = end($this->creationStack);
         $this->creationStack = array();
         throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa.");
     }
     $this->creationStack[$requestedType] = $requestedType;
     try {
         $args = $this->_resolveArguments($requestedType, $parameters, $arguments);
         unset($this->creationStack[$requestedType]);
     } catch (\Exception $e) {
         unset($this->creationStack[$requestedType]);
         throw $e;
     }
     switch (count($args)) {
         case 1:
             return new $type($args[0]);
         case 2:
             return new $type($args[0], $args[1]);
         case 3:
             return new $type($args[0], $args[1], $args[2]);
         case 4:
             return new $type($args[0], $args[1], $args[2], $args[3]);
         case 5:
             return new $type($args[0], $args[1], $args[2], $args[3], $args[4]);
         case 6:
             return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
         case 7:
             return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
         case 8:
             return new $type($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
         default:
             $reflection = new \ReflectionClass($type);
             return $reflection->newInstanceArgs($args);
     }
 }
コード例 #3
0
ファイル: Factory.php プロジェクト: Mohitsahu123/mtf
 /**
  * Create instance with call time arguments
  *
  * @param string $requestedType
  * @param array $arguments
  * @return object
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function create($requestedType, array $arguments = array())
 {
     $type = $this->config->getInstanceType($requestedType);
     $parameters = $this->definitions->getParameters($type);
     if ($parameters == null) {
         return new $type();
     }
     if (isset($this->creationStack[$requestedType])) {
         $lastFound = end($this->creationStack);
         $this->creationStack = array();
         throw new \LogicException("Circular dependency: {$requestedType} depends on {$lastFound} and vice versa.");
     }
     $this->creationStack[$requestedType] = $requestedType;
     try {
         $args = $this->_resolveArguments($requestedType, $parameters, $arguments);
         unset($this->creationStack[$requestedType]);
     } catch (\Exception $e) {
         unset($this->creationStack[$requestedType]);
         throw $e;
     }
     $reflection = new \ReflectionClass($type);
     return $reflection->newInstanceArgs($args);
 }
コード例 #4
0
ファイル: Config.php プロジェクト: Mohitsahu123/mtf
 /**
  * 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);
     }
 }
コード例 #5
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);
     }
 }