Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
9 
12 
14 {
20  protected $_omConfig;
21 
27  protected $_relations;
28 
34  protected $_classDefinitions;
35 
41  protected $_cache;
42 
48  protected $_cacheId;
49 
55  protected $_reader;
56 
62  protected $_intercepted = [];
63 
69  protected $_serviceClassTypes = ['Interceptor'];
70 
74  protected $_scopeList;
75 
79  private $serializer;
80 
93  public function __construct(
94  \Magento\Framework\Config\ReaderInterface $reader,
95  \Magento\Framework\Config\ScopeListInterface $scopeList,
96  \Magento\Framework\Cache\FrontendInterface $cache,
97  \Magento\Framework\ObjectManager\RelationsInterface $relations,
98  \Magento\Framework\Interception\ObjectManager\ConfigInterface $omConfig,
99  \Magento\Framework\ObjectManager\DefinitionInterface $classDefinitions,
100  $cacheId = 'interception',
101  SerializerInterface $serializer = null
102  ) {
103  $this->_omConfig = $omConfig;
104  $this->_relations = $relations;
105  $this->_classDefinitions = $classDefinitions;
106  $this->_cache = $cache;
107  $this->_cacheId = $cacheId;
108  $this->_reader = $reader;
109  $this->_scopeList = $scopeList;
110  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
111  ->get(Serialize::class);
112  $intercepted = $this->_cache->load($this->_cacheId);
113  if ($intercepted !== false) {
114  $this->_intercepted = $this->serializer->unserialize($intercepted);
115  } else {
116  $this->initialize($this->_classDefinitions->getClasses());
117  }
118  }
119 
126  public function initialize($classDefinitions = [])
127  {
128  $this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$this->_cacheId]);
129  $config = [];
130  foreach ($this->_scopeList->getAllScopes() as $scope) {
131  $config = array_replace_recursive($config, $this->_reader->read($scope));
132  }
133  unset($config['preferences']);
134  foreach ($config as $typeName => $typeConfig) {
135  if (!empty($typeConfig['plugins'])) {
136  $this->_intercepted[ltrim($typeName, '\\')] = true;
137  }
138  }
139  foreach ($config as $typeName => $typeConfig) {
140  $this->hasPlugins($typeName);
141  }
142  foreach ($classDefinitions as $class) {
143  $this->hasPlugins($class);
144  }
145  $this->_cache->save($this->serializer->serialize($this->_intercepted), $this->_cacheId);
146  }
147 
154  protected function _inheritInterception($type)
155  {
156  $type = ltrim($type, '\\');
157  if (!isset($this->_intercepted[$type])) {
158  $realType = $this->_omConfig->getOriginalInstanceType($type);
159  if ($type !== $realType) {
160  if ($this->_inheritInterception($realType)) {
161  $this->_intercepted[$type] = true;
162  return true;
163  }
164  } else {
165  $parts = explode('\\', $type);
166  if (!in_array(end($parts), $this->_serviceClassTypes) && $this->_relations->has($type)) {
167  $relations = $this->_relations->getParents($type);
168  foreach ($relations as $relation) {
169  if ($relation && $this->_inheritInterception($relation)) {
170  $this->_intercepted[$type] = true;
171  return true;
172  }
173  }
174  }
175  }
176  $this->_intercepted[$type] = false;
177  }
178  return $this->_intercepted[$type];
179  }
180 
184  public function hasPlugins($type)
185  {
186  if (isset($this->_intercepted[$type])) {
187  return $this->_intercepted[$type];
188  }
189  return $this->_inheritInterception($type);
190  }
191 }
$config
Definition: fraud_order.php:17
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74
__construct(\Magento\Framework\Config\ReaderInterface $reader, \Magento\Framework\Config\ScopeListInterface $scopeList, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Framework\ObjectManager\RelationsInterface $relations, \Magento\Framework\Interception\ObjectManager\ConfigInterface $omConfig, \Magento\Framework\ObjectManager\DefinitionInterface $classDefinitions, $cacheId='interception', SerializerInterface $serializer=null)
Definition: Config.php:93