本文整理汇总了PHP中Magento\Framework\Config\Dom\UrnResolver::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP UrnResolver::getRealPath方法的具体用法?PHP UrnResolver::getRealPath怎么用?PHP UrnResolver::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Config\Dom\UrnResolver
的用法示例。
在下文中一共展示了UrnResolver::getRealPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: 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');
}
示例3: 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);
}
示例4: 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');
}
}
示例5: 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');
}
}
示例6: 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;
}
示例7: 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;
}
示例8: __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;
}
示例9: 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;
}
示例10: 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());
}
示例11: 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;
}
示例12: getSchema
/**
* Get path to merged config schema
*
* @return string|null
*/
public function getSchema()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Cache/etc/cache.xsd');
}
示例13: testGetPerFileSchema
public function testGetPerFileSchema()
{
$this->assertEquals($this->urnResolver->getRealPath('urn:magento:framework:Api/etc/extension_attributes.xsd'), $this->model->getPerFileSchema());
}
示例14: __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');
}
示例15: getPerFileSchema
/**
* Get path to pre file validation schema
*
* @return null
*/
public function getPerFileSchema()
{
return $this->urnResolver->getRealPath('urn:magento:framework:Search/etc/search_request.xsd');
}