Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Dom.php
Go to the documentation of this file.
1 <?php
8 
15 
21 {
22  const PAGE_META_FILENAME_ATTRIBUTE = "filename";
23  const PAGE_META_NAME_ATTRIBUTE = "name";
24 
30  private $modulePathExtractor;
31 
37  private $validationUtil;
38 
49  public function __construct(
50  $xml,
51  $filename,
52  $exceptionCollector,
53  array $idAttributes = [],
54  $typeAttributeName = null,
55  $schemaFile = null,
56  $errorFormat = self::ERROR_FORMAT_DEFAULT
57  ) {
58  $this->modulePathExtractor = new ModulePathExtractor();
59  $this->validationUtil = new DuplicateNodeValidationUtil('name', $exceptionCollector);
60  parent::__construct(
61  $xml,
62  $filename,
63  $exceptionCollector,
64  $idAttributes,
68  );
69  }
70 
78  public function initDom($xml, $filename = null)
79  {
80  $dom = parent::initDom($xml, $filename);
81 
82  $pagesNode = $dom->getElementsByTagName('pages')->item(0);
83  $this->validationUtil->validateChildUniqueness(
84  $pagesNode,
85  $filename,
86  $pagesNode->getAttribute(self::PAGE_META_NAME_ATTRIBUTE)
87  );
88  $pageNodes = $dom->getElementsByTagName('page');
89  $currentModule =
90  $this->modulePathExtractor->extractModuleName($filename) .
91  '_' .
92  $this->modulePathExtractor->getExtensionPath($filename);
93  foreach ($pageNodes as $pageNode) {
94  $pageModule = $pageNode->getAttribute("module");
95  $pageName = $pageNode->getAttribute("name");
96  if ($pageModule !== $currentModule) {
97  if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
98  print(
99  "Page Module does not match path Module. " .
100  "(Page, Module): ($pageName, $pageModule) - Path Module: $currentModule" .
101  PHP_EOL
102  );
103  }
104  }
105  $pageNode->setAttribute(self::PAGE_META_FILENAME_ATTRIBUTE, $filename);
106  }
107  return $dom;
108  }
109 }
__construct( $xml, $filename, $exceptionCollector, array $idAttributes=[], $typeAttributeName=null, $schemaFile=null, $errorFormat=self::ERROR_FORMAT_DEFAULT)
Definition: Dom.php:49