'Magento\Theme', 'adminhtml' => 'Magento\Adminhtml', ]; /** * Namespaces to analyze * * Format: {Namespace}|{Namespace}|... * * @var string */ protected $_namespaces; /** * List of routers * * Format: array( * '{Router}' => '{Module_Name}' * ) * * @var array */ protected $_mapRouters = []; /** * List of layout blocks * * Format: array( * '{Area}' => array( * '{Block_Name}' => array('{Module_Name}' => '{Module_Name}') * )) * * @var array */ protected $_mapLayoutBlocks = []; /** * List of layout handles * * Format: array( * '{Area}' => array( * '{Handle_Name}' => array('{Module_Name}' => '{Module_Name}') * )) * * @var array */ protected $_mapLayoutHandles = []; /** * Unknown layout handle */ const EXCEPTION_TYPE_UNKNOWN_HANDLE = 'UNKNOWN_HANDLE'; /** * Unknown layout block */ const EXCEPTION_TYPE_UNKNOWN_BLOCK = 'UNKNOWN_BLOCK'; /** * Undefined dependency */ const EXCEPTION_TYPE_UNDEFINED_DEPENDENCY = 'UNDEFINED_DEPENDENCY'; /** * Constructor * * @param array $mapRouters * @param array $mapLayoutBlocks * @param array $mapLayoutHandles */ public function __construct(array $mapRouters, array $mapLayoutBlocks, array $mapLayoutHandles) { $this->_mapRouters = $mapRouters; $this->_mapLayoutBlocks = $mapLayoutBlocks; $this->_mapLayoutHandles = $mapLayoutHandles; $this->_namespaces = implode('|', \Magento\Framework\App\Utility\Files::init()->getNamespaces()); } /** * Retrieve dependencies information for current module * * @param string $currentModule * @param string $fileType * @param string $file * @param string $contents * @return array */ public function getDependencyInfo($currentModule, $fileType, $file, &$contents) { if ('layout' != $fileType) { return []; } $attributes = $this->_caseAttributeModule($currentModule, $contents); $blocks = $this->_caseElementBlock($currentModule, $contents); $actions = $this->_caseElementAction($currentModule, $contents); $handle = $this->_caseLayoutHandle($currentModule, $file, $contents); $handleParents = $this->_caseLayoutHandleParent($currentModule, $file, $contents); $handleUpdates = $this->_caseLayoutHandleUpdate($currentModule, $file, $contents); $references = $this->_caseLayoutReference($currentModule, $file, $contents); $dependencies = array_merge( $attributes, $blocks, $actions, $handle, $handleParents, $handleUpdates, $references ); return $dependencies; } /** * Check dependencies for 'module' attribute * * Ex.: * * @param $currentModule * @param $contents * @return array */ protected function _caseAttributeModule($currentModule, &$contents) { $patterns = [ '/(?<.+module\s*=\s*[\'"](?' . $this->_namespaces . ')[_\\\\]' . '(?[A-Z][a-zA-Z]+)[\'"].*>)/' => \Magento\Test\Integrity\DependencyTest::TYPE_SOFT, ]; return $this->_checkDependenciesByRegexp($currentModule, $contents, $patterns); } /** * Check dependencies for element * * Ex.: * * * @param $currentModule * @param $contents * @return array */ protected function _caseElementBlock($currentModule, &$contents) { $patterns = [ '/(?' . $this->_namespaces . ')[_\\\\]' . '(?[A-Z][a-zA-Z]+)[_\\\\]' . '(?:[A-Z][a-zA-Z]+[_\\\\]?){1,}[\'"].*>)/' => \Magento\Test\Integrity\DependencyTest::TYPE_HARD, '/(?' . $this->_namespaces . ')[_\\\\]' . '(?[A-Z][a-zA-Z]+)::[\w\/\.]+[\'"].*>)/' => \Magento\Test\Integrity\DependencyTest::TYPE_SOFT, ]; return $this->_checkDependenciesByRegexp($currentModule, $contents, $patterns); } /** * Check dependencies for element * * Ex.: {name} *