_omConfig = $omConfig; $this->_relations = $relations; $this->_classDefinitions = $classDefinitions; $this->_cache = $cache; $this->_cacheId = $cacheId; $this->_reader = $reader; $this->_scopeList = $scopeList; $this->cacheManager = $cacheManager ?? \Magento\Framework\App\ObjectManager::getInstance()->get(CacheManager::class); $intercepted = $this->cacheManager->load($cacheId); if ($intercepted !== null) { $this->_intercepted = $intercepted; } else { $this->initializeUncompiled($this->_classDefinitions->getClasses()); } } /** * Initialize interception config * * @param array $classDefinitions * @return void */ public function initialize($classDefinitions = []) { $this->generateIntercepted($classDefinitions); $this->cacheManager->saveCompiled($this->_cacheId, $this->_intercepted); } /** * Process interception inheritance * * @param string $type * @return bool */ protected function _inheritInterception($type) { $type = ltrim($type, '\\'); if (!isset($this->_intercepted[$type])) { $realType = $this->_omConfig->getOriginalInstanceType($type); if ($type !== $realType) { if ($this->_inheritInterception($realType)) { $this->_intercepted[$type] = true; return true; } } else { $parts = explode('\\', $type); if (!in_array(end($parts), $this->_serviceClassTypes) && $this->_relations->has($type)) { $relations = $this->_relations->getParents($type); foreach ($relations as $relation) { if ($relation && $this->_inheritInterception($relation)) { $this->_intercepted[$type] = true; return true; } } } } $this->_intercepted[$type] = false; } return $this->_intercepted[$type]; } /** * @inheritdoc */ public function hasPlugins($type) { if (isset($this->_intercepted[$type])) { return $this->_intercepted[$type]; } return $this->_inheritInterception($type); } /** * Write interception config to cache * * @param array $classDefinitions */ private function initializeUncompiled($classDefinitions = []) { $this->cacheManager->clean($this->_cacheId); $this->generateIntercepted($classDefinitions); $this->cacheManager->save($this->_cacheId, $this->_intercepted); } /** * Generate intercepted array to store in compiled metadata or frontend cache * * @param array $classDefinitions */ private function generateIntercepted($classDefinitions) { $config = []; foreach ($this->_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($typeName); } foreach ($classDefinitions as $class) { $this->hasPlugins($class); } } }