コード例 #1
0
ファイル: DomTest.php プロジェクト: nblair/magescotch
 /**
  * @param string $xmlFile
  * @param string $newXmlFile
  * @param array $ids
  * @param string|null $typeAttributeName
  * @param string $expectedXmlFile
  * @dataProvider mergeDataProvider
  */
 public function testMerge($xmlFile, $newXmlFile, $ids, $typeAttributeName, $expectedXmlFile)
 {
     $xml = file_get_contents(__DIR__ . "/_files/dom/{$xmlFile}");
     $newXml = file_get_contents(__DIR__ . "/_files/dom/{$newXmlFile}");
     $config = new \Magento\Framework\Config\Dom($xml, $this->validationStateMock, $ids, $typeAttributeName);
     $config->merge($newXml);
     $this->assertXmlStringEqualsXmlFile(__DIR__ . "/_files/dom/{$expectedXmlFile}", $config->getDom()->saveXML());
 }
コード例 #2
0
 /**
  * Init configuration
  *
  * @param string $groupsFile
  * @return $this
  * @throws Exception
  */
 public function init($groupsFile)
 {
     $xmlFile = $this->getRootDir() . $groupsFile;
     if (!is_file($xmlFile)) {
         throw new Exception('Invalid groups filename: ' . $xmlFile);
     }
     $xml = file_get_contents($xmlFile);
     $document = new \Magento\Framework\Config\Dom($xml, $this->validationState);
     if (!$document->validate($this->getRootDir() . 'etc/' . self::CONFIGURATION_SCHEMA)) {
         throw new Exception('XML file is invalid.');
     }
     $this->xml = new \DOMXPath($document->getDom());
     return $this;
 }
コード例 #3
0
ファイル: Map.php プロジェクト: okite11/frames21
 /**
  * Init configuration
  *
  * @param string $mapFile
  * @return $this
  * @throws Exception
  */
 protected function init($mapFile)
 {
     $this->ignoredDocuments = [];
     $this->wildcards = null;
     $configFile = $this->getRootDir() . $mapFile;
     if (!is_file($configFile)) {
         throw new Exception('Invalid map filename: ' . $configFile);
     }
     $xml = file_get_contents($configFile);
     $document = new \Magento\Framework\Config\Dom($xml);
     if (!$document->validate($this->getRootDir() . 'etc/' . self::CONFIGURATION_SCHEMA)) {
         throw new Exception('XML file is invalid.');
     }
     $this->xml = new \DOMXPath($document->getDom());
     return $this;
 }
コード例 #4
0
 /**
  * Validating xml file
  *
  * @return $this
  * @throws Exception
  */
 protected function validate()
 {
     $mapFile = $this->config->getOption(self::MAP_FILE_OPTION);
     $rootDir = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR;
     $configFile = $rootDir . $mapFile;
     if (!is_file($configFile)) {
         throw new Exception('Invalid map filename: ' . $configFile);
     }
     $xml = file_get_contents($configFile);
     $document = $document = new \Magento\Framework\Config\Dom($xml, new \Magento\Framework\App\Arguments\ValidationState(\Magento\Framework\App\State::MODE_DEVELOPER));
     if (!$document->validate($rootDir . 'etc/' . self::CONFIGURATION_SCHEMA)) {
         throw new Exception('XML file is invalid.');
     }
     $this->xml = new \DOMXPath($document->getDom());
     return $this;
 }
コード例 #5
0
ファイル: Config.php プロジェクト: okite11/frames21
 /**
  * Init configuration
  *
  * @param string $configFile
  * @return $this
  * @throws Exception
  */
 public function init($configFile = null)
 {
     if ($configFile === null) {
         $configFile = $this->getConfigDirectoryPath() . self::CONFIGURATION_FILE;
     }
     if (empty($configFile) || !file_exists($configFile)) {
         throw new Exception('Invalid config filename: ' . $configFile);
     }
     $xml = file_get_contents($configFile);
     $document = new \Magento\Framework\Config\Dom($xml);
     if (!$document->validate($this->getConfigDirectoryPath() . self::CONFIGURATION_SCHEMA)) {
         throw new Exception('XML file is invalid.');
     }
     $this->config = new \DOMXPath($document->getDom());
     $this->options = null;
     return $this;
 }
コード例 #6
0
ファイル: Loader.php プロジェクト: Mohitsahu123/mtf
 /**
  * Load configuration
  *
  * @return array
  */
 public function load()
 {
     $localConfig = new \Magento\Framework\Config\Dom('<config/>', $this->_idAttributes);
     $localConfigFile = $this->_dir . '/' . self::LOCAL_CONFIG_FILE;
     if (file_exists($localConfigFile)) {
         // 1. app/etc/local.xml
         $localConfig->merge(file_get_contents($localConfigFile));
         // 2. app/etc/<dir>/<file>.xml
         if (preg_match('/^[a-z\\d_-]+(\\/|\\\\)+[a-z\\d_-]+\\.xml$/', $this->_customFile)) {
             $localConfigExtraFile = $this->_dir . '/' . $this->_customFile;
             $localConfig->merge(file_get_contents($localConfigExtraFile));
         }
     }
     $arrayNodeConfig = new \Magento\Framework\Config\Dom\ArrayNodeConfig(new \Magento\Framework\Config\Dom\NodePathMatcher(), $this->_idAttributes);
     $converter = new \Magento\Framework\Config\Converter\Dom\Flat($arrayNodeConfig);
     $result = $converter->convert($localConfig->getDom());
     return !empty($result['config']) ? $result['config'] : array();
 }
コード例 #7
0
 /**
  * Validating xml file
  *
  * @return $this
  * @throws Exception
  */
 protected function validate()
 {
     $mapFile = $this->config->getOption(self::MAP_FILE_OPTION);
     $rootDir = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR;
     $configFile = $rootDir . $mapFile;
     if (!is_file($configFile)) {
         throw new Exception('Invalid map filename: ' . $configFile);
     }
     $xml = file_get_contents($configFile);
     $document = $document = new \Magento\Framework\Config\Dom($xml, new \Magento\Framework\App\Arguments\ValidationState(\Magento\Framework\App\State::MODE_DEVELOPER));
     $schemaFileName = $rootDir . 'etc/' . self::CONFIGURATION_SCHEMA;
     if (!$document->validate($schemaFileName)) {
         $errors = $document->validateDomDocument($document->getDom(), $schemaFileName, $document::ERROR_FORMAT_DEFAULT);
         foreach ($errors as $error) {
             echo $error . PHP_EOL;
         }
         throw new Exception('XML file is invalid.');
     }
     $this->xml = new \DOMXPath($document->getDom());
     return $this;
 }