([a-zA-Z]*)):module:(?([A-Za-z0-9\_]*)):(?(.+))/'; $frameworkPattern = '/urn:(?([a-zA-Z]*)):(?(framework[A-Za-z\-]*)):(?(.+))/'; if (preg_match($modulePattern, $schema, $matches)) { //urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd $package = $componentRegistrar ->getPath(ComponentRegistrar::MODULE, $matches['module']); } else if (preg_match($frameworkPattern, $schema, $matches)) { //urn:magento:framework:Module/etc/module.xsd //urn:magento:framework-amqp:Module/etc/module.xsd $package = $componentRegistrar ->getPath(ComponentRegistrar::LIBRARY, $matches['vendor'] . '/' . $matches['framework']); } else { throw new NotFoundException(new Phrase("Unsupported format of schema location: '%1'", [$schema])); } $schemaPath = $package . '/' . $matches['path']; if (empty($package) || !file_exists($schemaPath)) { throw new NotFoundException( new Phrase("Could not locate schema: '%1' at '%2'", [$schema, $schemaPath]) ); } return $schemaPath; } /** * Callback registered for libxml to resolve URN to the file path * * @param string $public * @param string $system * @param array $context * @return resource * @throws LocalizedException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function registerEntityLoader($public, $system, $context) { if (strpos($system, 'urn:') === 0) { $filePath = $this->getRealPath($system); } else { if (file_exists($system)) { $filePath = $system; } else { throw new LocalizedException(new Phrase("File '%system' cannot be found", ['system' => $system])); } } return fopen($filePath, "r"); } }