forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-42196: Magento components loaded from vendor directory - XSD …
…filepath resolution - Implemented URN resolver
- Loading branch information
Maksym Savich
committed
Sep 8, 2015
1 parent
6f1ad53
commit 6379732
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* Resolve URN path to a real schema path | ||
*/ | ||
namespace Magento\Framework\Config\Dom; | ||
|
||
class UrnResolver | ||
{ | ||
/** | ||
* @var \Magento\Framework\Component\ModuleRegistrar | ||
*/ | ||
private static $moduleRegistrar; | ||
|
||
/** | ||
* @var \Magento\Framework\Component\LibraryRegistrar | ||
*/ | ||
private static $libraryRegistrar; | ||
|
||
/** | ||
* Get real file path by it's URN reference | ||
* | ||
* @param $schemaFileName | ||
* @return string | ||
*/ | ||
public static function getRealPath($schemaFileName) | ||
{ | ||
if (substr($schemaFileName, 0, 4) == 'urn:') { | ||
if (!self::$moduleRegistrar) { | ||
self::$moduleRegistrar = new \Magento\Framework\Component\ModuleRegistrar(); | ||
} | ||
if (!self::$libraryRegistrar) { | ||
self::$libraryRegistrar = new \Magento\Framework\Component\LibraryRegistrar(); | ||
} | ||
// resolve schema location | ||
// urn:magento:module:catalog:etc/catalog_attributes.xsd | ||
// 0 : urn, 1: magento, 2: module, 3: catalog, 4: etc/catalog_attributes.xsd | ||
// BP/app/code/Magento/Catalog/etc/catalog_attributes.xsd | ||
// BP/vendor/magento/module-catalog/etc/catalog_attributes.xsd | ||
$urnParts = explode(':', $schemaFileName); | ||
if ($urnParts[2] == 'module') { | ||
$appModulePath = str_replace(' ', '', ucwords(str_replace('-', ' ', $urnParts[3]))); | ||
$moduleName = ucfirst($urnParts[1]) . '_' . $appModulePath; | ||
$appSchemaPath = self::$moduleRegistrar->getPath($moduleName) . '/' . $urnParts[4]; | ||
} else if ($urnParts[2] == 'library') { | ||
// urn:magento:library:framework:Module/etc/module.xsd | ||
// 0: urn, 1: magento, 2:library, 3: framework, 4: Module/etc/module.xsd | ||
$moduleName = $urnParts[1] . '/' . $urnParts[3]; | ||
$appSchemaPath = self::$libraryRegistrar->getPath($moduleName) . '/' . $urnParts[4]; | ||
} else { | ||
throw new \UnexpectedValueException("Unsupported format of schema location: " . $schemaFileName); | ||
} | ||
if (!empty($appSchemaPath) && file_exists($appSchemaPath)) { | ||
$schemaFileName = $appSchemaPath; | ||
} else { | ||
throw new \UnexpectedValueException("Could not locate schema: " . $schemaFileName); | ||
} | ||
} | ||
return $schemaFileName; | ||
} | ||
} |