Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UrnResolver.php
Go to the documentation of this file.
1 <?php
11 
16 
22 {
30  public function getRealPath($schema)
31  {
32  if (strpos($schema, 'urn:') !== 0) {
33  return $schema;
34  }
35 
37  $matches = [];
38  $modulePattern = '/urn:(?<vendor>([a-zA-Z]*)):module:(?<module>([A-Za-z0-9\_]*)):(?<path>(.+))/';
39  $frameworkPattern = '/urn:(?<vendor>([a-zA-Z]*)):(?<framework>(framework[A-Za-z\-]*)):(?<path>(.+))/';
40  $setupPattern = '/urn:(?<vendor>([a-zA-Z]*)):(?<setup>(setup[A-Za-z\-]*)):(?<path>(.+))/';
41  if (preg_match($modulePattern, $schema, $matches)) {
42  //urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd
43  $package = $componentRegistrar
44  ->getPath(ComponentRegistrar::MODULE, $matches['module']);
45  } elseif (preg_match($frameworkPattern, $schema, $matches)) {
46  //urn:magento:framework:Module/etc/module.xsd
47  //urn:magento:framework-amqp:Module/etc/module.xsd
48  $package = $componentRegistrar
49  ->getPath(ComponentRegistrar::LIBRARY, $matches['vendor'] . '/' . $matches['framework']);
50  } elseif (preg_match($setupPattern, $schema, $matches)) {
51  //urn:magento:setup:
52  $package = $componentRegistrar
53  ->getPath(ComponentRegistrar::SETUP, $matches['vendor'] . '/' . $matches['setup']);
54  } else {
55  throw new NotFoundException(new Phrase("Unsupported format of schema location: '%1'", [$schema]));
56  }
57  $schemaPath = $package . '/' . $matches['path'];
58  if (empty($package) || !file_exists($schemaPath)) {
59  throw new NotFoundException(
60  new Phrase("Could not locate schema: '%1' at '%2'", [$schema, $schemaPath])
61  );
62  }
63  return $schemaPath;
64  }
65 
76  public function registerEntityLoader($public, $system, $context)
77  {
78  if (strpos($system, 'urn:') === 0) {
79  $filePath = $this->getRealPath($system);
80  } else {
81  if (file_exists($system)) {
82  $filePath = $system;
83  } else {
84  throw new LocalizedException(new Phrase("File '%system' cannot be found", ['system' => $system]));
85  }
86  }
87  return fopen($filePath, "r");
88  }
89 }
$componentRegistrar
Definition: bootstrap.php:23
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
registerEntityLoader($public, $system, $context)
Definition: UrnResolver.php:76