/** * Loads the full module list information. Excludes modules specified in $exclude. * * @param array $exclude * @throws \Magento\Framework\Exception\LocalizedException * @return array */ public function load(array $exclude = []) { $result = []; foreach ($this->getModuleConfigs() as list($file, $contents)) { try { $this->parser->loadXML($contents); } catch (\Magento\Framework\Exception\LocalizedException $e) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid Document: %1%2 Error: %3', [$file, PHP_EOL, $e->getMessage()]), $e); } $data = $this->converter->convert($this->parser->getDom()); $name = key($data); if (!in_array($name, $exclude)) { $result[$name] = $data[$name]; } } return $this->sortBySequence($result); }
/** * Loads the full module list information * * @throws \Magento\Framework\Exception * @return array */ public function load() { $result = []; $dir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES); foreach ($dir->search('*/*/etc/module.xml') as $file) { $contents = $dir->readFile($file); try { $this->parser->loadXML($contents); } catch (\Magento\Framework\Exception $e) { throw new \Magento\Framework\Exception('Invalid Document: ' . $file . PHP_EOL . ' Error: ' . $e->getMessage(), $e->getCode(), $e); } $data = $this->converter->convert($this->parser->getDom()); $name = key($data); $result[$name] = $data[$name]; } return $this->sortBySequence($result); }
/** * Convert XML document into array. * * @param string $xmlRequestBody XML document * @return array Data converted from XML document to array. Root node is excluded from response. * @throws \InvalidArgumentException In case of invalid argument type. * @throws \Magento\Framework\Webapi\Exception If decoding error occurs. */ public function deserialize($xmlRequestBody) { if (!is_string($xmlRequestBody)) { throw new \InvalidArgumentException(sprintf('"%s" data type is invalid. String is expected.', gettype($xmlRequestBody))); } /** Disable external entity loading to prevent possible vulnerability */ $previousLoaderState = libxml_disable_entity_loader(true); set_error_handler([$this, 'handleErrors']); $this->_xmlParser->loadXML($xmlRequestBody); restore_error_handler(); libxml_disable_entity_loader($previousLoaderState); /** Process errors during XML parsing. */ if ($this->_errorMessage !== null) { if ($this->_appState->getMode() !== State::MODE_DEVELOPER) { $exceptionMessage = new Phrase('Decoding error.'); } else { $exceptionMessage = 'Decoding Error: ' . $this->_errorMessage; } throw new \Magento\Framework\Webapi\Exception($exceptionMessage); } $data = $this->_xmlParser->xmlToArray(); /** Data will always have exactly one element so it is safe to call reset here. */ return reset($data); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage DOMDocument::loadXML(): Opening and ending tag mismatch */ public function testLoadXmlInvalid() { $sampleInvalidXml = '<?xml version="1.0"?><config></onfig>'; $this->parser->initErrorHandler(); $this->parser->loadXML($sampleInvalidXml); }