本文整理汇总了PHP中Magento\Framework\Config\Dom\UrnResolver类的典型用法代码示例。如果您正苦于以下问题:PHP UrnResolver类的具体用法?PHP UrnResolver怎么用?PHP UrnResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UrnResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Build DOM with initial XML contents and specifying identifier attributes for merging
*
* Format of $schema: Absolute schema file path or URN
* Format of $idAttributes: array('name', 'id')
* Format of $contextXPath: array('/config/ui')
* The path to ID attribute name should not include any attribute notations or modifiers -- only node names
*
* @param UrnResolver $urnResolver
* @param string $schema Absolute schema file path or URN
* @param bool $isMergeSimpleXMLElement
* @param array $contextXPath
* @param array $idAttributes
*/
public function __construct(UrnResolver $urnResolver, $schema, $isMergeSimpleXMLElement = false, array $contextXPath = [], array $idAttributes = [])
{
$this->schemaFilePath = $urnResolver->getRealPath($schema);
$this->isMergeSimpleXMLElement = $isMergeSimpleXMLElement;
$this->contextXPath = $contextXPath;
$this->idAttributes = $idAttributes;
}
示例2: validateDomDocument
/**
* Validate dom document
*
* @param \DOMDocument $dom
* @param string $schema Absolute schema file path or URN
* @param string $errorFormat
* @return array of errors
* @throws \Exception
*/
public static function validateDomDocument(\DOMDocument $dom, $schema, $errorFormat = self::ERROR_FORMAT_DEFAULT)
{
if (!function_exists('libxml_set_external_entity_loader')) {
return [];
}
if (!self::$urnResolver) {
self::$urnResolver = new UrnResolver();
}
$schema = self::$urnResolver->getRealPath($schema);
libxml_use_internal_errors(true);
libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
$errors = [];
try {
$result = $dom->schemaValidate($schema);
if (!$result) {
$errors = self::getXmlErrors($errorFormat);
}
} catch (\Exception $exception) {
libxml_use_internal_errors(false);
throw $exception;
}
libxml_set_external_entity_loader(null);
libxml_use_internal_errors(false);
return $errors;
}
示例3: validateDomDocument
/**
* Validate dom document
*
* @param \DOMDocument $dom
* @param string $schema Absolute schema file path or URN
* @param string $errorFormat
* @return array of errors
* @throws \Exception
*/
public static function validateDomDocument(
\DOMDocument $dom,
$schema,
$errorFormat = self::ERROR_FORMAT_DEFAULT
) {
if (!self::$urnResolver) {
self::$urnResolver = new UrnResolver();
}
$schema = self::$urnResolver->getRealPath($schema);
libxml_use_internal_errors(true);
libxml_set_external_entity_loader([self::$urnResolver, 'registerEntityLoader']);
try {
$result = $dom->schemaValidate($schema);
$errors = [];
if (!$result) {
$validationErrors = libxml_get_errors();
if (count($validationErrors)) {
foreach ($validationErrors as $error) {
$errors[] = self::_renderErrorMessage($error, $errorFormat);
}
} else {
$errors[] = 'Unknown validation error';
}
}
} catch (\Exception $exception) {
libxml_use_internal_errors(false);
throw $exception;
}
libxml_set_external_entity_loader(null);
libxml_use_internal_errors(false);
return $errors;
}
示例4: __construct
/**
* Initialize dependencies.
*
* @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
*/
public function __construct(\Magento\Framework\Config\Dom\UrnResolver $urnResolver)
{
$this->schema = $urnResolver->getRealPath('urn:magento:framework:Communication/etc/communication.xsd');
$this->perFileSchema = $urnResolver->getRealPath('urn:magento:framework:Communication/etc/communication.xsd');
}
示例5: __construct
/**
* @param \Magento\Framework\Config\DomFactory $domConfigFactory
* @param \Magento\Framework\Config\Dom\UrnResolver $urnResolver
*/
public function __construct(\Magento\Framework\Config\DomFactory $domConfigFactory, UrnResolver $urnResolver)
{
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/page_layout.xsd'), self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath('urn:magento:framework:View/Layout/etc/layout_merged.xsd')];
}
示例6: testGetSchemaFile
public function testGetSchemaFile()
{
$config = new \Magento\Framework\Config\Theme($this->urnResolverMock, null);
$this->urnResolverMock->expects($this->exactly(2))->method('getRealPath')->with('urn:magento:framework:Config/etc/theme.xsd')->willReturn($this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd'));
$this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Config/etc/theme.xsd'), $config->getSchemaFile());
$this->assertFileExists($config->getSchemaFile());
}
示例7: testReadWithInvalidXml
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Invalid XML in file
*/
public function testReadWithInvalidXml()
{
$this->_schemaLocatorMock->expects($this->any())->method('getPerFileSchema')->will($this->returnValue($this->urnResolver->getRealPath('urn:magento:framework:Config/Test/Unit/_files/reader/schema.xsd')));
$this->_validationStateMock->expects($this->any())->method('isValidationRequired')->willReturn(true);
$model = new Filesystem($this->_fileResolverMock, $this->_converterMock, $this->_schemaLocatorMock, $this->_validationStateMock, 'fileName', []);
$this->_fileResolverMock->expects($this->once())->method('get')->will($this->returnValue([$this->_file]));
$model->read('scope');
}
示例8: testFileSchemaUsingInvalidXml
public function testFileSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_widget.xml';
$schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget_file.xsd');
$this->_validateFileExpectFailure($xmlFile, $schema);
}
示例9: testFileSchemaUsingInvalidXml
public function testFileSchemaUsingInvalidXml()
{
$xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if (!$errors) {
$this->fail('There is a problem with the schema. A known bad XML file passed validation');
}
}
示例10: testFileSchemaUsingInvalidXml
public function testFileSchemaUsingInvalidXml()
{
if (!function_exists('libxml_set_external_entity_loader')) {
$this->markTestSkipped('Skipped due to MAGETWO-45033');
}
$xmlFile = __DIR__ . '/_files/invalid_fieldset.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$schema = $this->urnResolver->getRealPath('urn:magento:framework:DataObject/etc/fieldset_file.xsd');
$errors = \Magento\Framework\Config\Dom::validateDomDocument($dom, $schema);
if (!$errors) {
$this->fail('There is a problem with the schema. A known bad XML file passed validation');
}
}
示例11: getUrnDictionary
/**
* Get an array of URNs
*
* @param OutputInterface $output
* @return array
*/
private function getUrnDictionary(OutputInterface $output)
{
$files = $this->filesUtility->getXmlCatalogFiles('*.xml');
$files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd'));
$urns = [];
foreach ($files as $file) {
$content = $this->rootDirRead->readFile($this->rootDirRead->getRelativePath($file[0]));
$matches = [];
preg_match_all('/schemaLocation="(urn\\:magento\\:[^"]*)"/i', $content, $matches);
if (isset($matches[1])) {
$urns = array_merge($urns, $matches[1]);
}
}
$urns = array_unique($urns);
$paths = [];
foreach ($urns as $urn) {
try {
$paths[$urn] = $this->urnResolver->getRealPath($urn);
} catch (\Exception $e) {
// don't add unsupported element to array
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($e->getMessage());
}
}
}
return $paths;
}
示例12: testGetSchemaFile
/**
* Test schema file exists
*/
public function testGetSchemaFile()
{
$this->_initConfig();
$this->assertEquals(
$this->urnResolver->getRealPath('urn:magento:framework:Validator/etc/validation.xsd'),
$this->_config->getSchemaFile()
);
$this->assertFileExists($this->_config->getSchemaFile());
}
示例13: readXsdFiles
/**
* Get merged xsd file
*
* @param array $fileList
* @param string $baseXsd
* @return null|string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function readXsdFiles($fileList, $baseXsd = null)
{
$baseXsd = new \DOMDocument();
$baseXsdPath = $this->urnResolver->getRealPath($this->searchFilesPattern . $this->fileName);
$baseXsd->load($baseXsdPath);
$configMerge = null;
foreach ($fileList as $key => $content) {
if ($key == $baseXsdPath) {
continue;
}
try {
if (!empty($content)) {
if ($configMerge) {
$configMerge = $this->mergeXsd($configMerge, $content);
} else {
$configMerge = $this->mergeXsd($baseXsd->saveXML(), $content);
}
}
} catch (\Magento\Framework\Config\Dom\ValidationException $e) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XSD in file %1:\n%2", [$key, $e->getMessage()]));
}
}
return $configMerge;
}
示例14: _getFileXsd
/**
* Returns the name of the XSD file to be used to validate partial XML
*
* @return string
*/
protected function _getFileXsd()
{
return $this->urnResolver->getRealPath('urn:magento:module:Magento_Payment:etc/payment_file.xsd');
}
示例15: getSchema
/**
* Get path to merged config schema
*
* @return string
*/
public function getSchema()
{
return $this->urnResolver->getRealPath('urn:magento:framework:ObjectManager/etc/config.xsd');
}