本文整理汇总了PHP中Magento\Framework\Component\ComponentRegistrar::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP ComponentRegistrar::getPath方法的具体用法?PHP ComponentRegistrar::getPath怎么用?PHP ComponentRegistrar::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Component\ComponentRegistrar
的用法示例。
在下文中一共展示了ComponentRegistrar::getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRealPath
/**
* Get real file path by it's URN reference
*
* @param string $schema
* @return string
* @throws NotFoundException
*/
public function getRealPath($schema)
{
if (strpos($schema, 'urn:') !== 0) {
return $schema;
}
$componentRegistrar = new ComponentRegistrar();
$matches = [];
$modulePattern = '/urn:(?<vendor>([a-zA-Z]*)):module:(?<module>([A-Za-z\\_]*)):(?<path>(.+))/';
$frameworkPattern = '/urn:(?<vendor>([a-zA-Z]*)):(?<framework>(framework[A-Za-z\\-]*)):(?<path>(.+))/';
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;
}
示例2: assertFixturesRegistered
private function assertFixturesRegistered()
{
$this->assertSame(__DIR__ . '/_files/components/b', $this->componentRegistrar->getPath(ComponentRegistrar::LIBRARY, self::LIBRARY_NAME));
$this->assertSame(__DIR__ . '/_files/components', $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::MODULE_NAME));
$this->assertSame(__DIR__ . '/_files/components/a/aa/aaa', $this->componentRegistrar->getPath(ComponentRegistrar::THEME, self::THEME_NAME));
$this->assertSame(__DIR__ . '/_files/components/a/aa', $this->componentRegistrar->getPath(ComponentRegistrar::LANGUAGE, self::LANGUAGE_NAME));
}
示例3: getRealPath
/**
* Get real file path by it's URN reference
*
* @param string $schema
* @return string
* @throws \UnexpectedValueException
*/
public function getRealPath($schema)
{
$componentRegistrar = new ComponentRegistrar();
if (substr($schema, 0, 4) == 'urn:') {
// resolve schema location
$urnParts = explode(':', $schema);
if ($urnParts[2] == 'module') {
// urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd
// 0 : urn, 1: magento, 2: module, 3: Magento_Catalog, 4: etc/catalog_attributes.xsd
// moduleName -> Magento_Catalog
$schemaPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $urnParts[3]) . '/' . $urnParts[4];
} else {
if (strpos($urnParts[2], 'framework') === 0) {
// urn:magento:framework:Module/etc/module.xsd
// 0: urn, 1: magento, 2: framework, 3: Module/etc/module.xsd
// libaryName -> magento/framework
$libraryName = $urnParts[1] . '/' . $urnParts[2];
$schemaPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, $libraryName) . '/' . $urnParts[3];
} else {
throw new \UnexpectedValueException("Unsupported format of schema location: " . $schema);
}
}
if (!empty($schemaPath) && file_exists($schemaPath)) {
$schema = $schemaPath;
} else {
throw new \UnexpectedValueException("Could not locate schema: '" . $schema . "' at '" . $schemaPath . "'");
}
}
return $schema;
}
示例4: install
/**
* @inheritdoc
*/
public function install()
{
$this->eavConfig->clear();
$importModel = $this->importModel;
$importModel->setData(['entity' => 'catalog_product', 'behavior' => 'append', 'import_images_file_dir' => 'pub/media/catalog/product', Import::FIELD_NAME_VALIDATION_STRATEGY => ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS]);
$source = $this->csvSourceFactory->create(['file' => 'fixtures/products.csv', 'directory' => $this->readFactory->create($this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_ConfigurableSampleData'))]);
$currentPath = getcwd();
chdir(BP);
$importModel->validateSource($source);
$importModel->importSource();
chdir($currentPath);
$this->eavConfig->clear();
$this->reindex();
}
示例5: getPackageName
/**
* Get package name of a theme by its full theme path
*
* @param string $themePath
* @return string
* @throws \Zend_Json_Exception
*/
public function getPackageName($themePath)
{
$themePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
$themeDir = $this->readDirFactory->create($themePath);
if ($themeDir->isExist('composer.json')) {
$rawData = [];
$themeFile = $themeDir->readFile('composer.json');
if ($themeFile) {
$rawData = \Zend_Json::decode($themeFile);
}
return isset($rawData['name']) ? $rawData['name'] : '';
}
return '';
}
示例6: isModuleExists
/**
* Check module existence
*
* @param string $moduleName
* @return bool
*/
public function isModuleExists($moduleName)
{
$key = __METHOD__ . "/{$moduleName}";
if (!isset(self::$_cache[$key])) {
self::$_cache[$key] = file_exists($this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName));
}
return self::$_cache[$key];
}
示例7: testGetRealPathWithModuleUrn
public function testGetRealPathWithModuleUrn()
{
$xsdUrn = 'urn:magento:module:Magento_Customer:etc/address_formats.xsd';
$componentRegistrar = new ComponentRegistrar();
$xsdPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Customer') . '/etc/address_formats.xsd';
$result = $this->urnResolver->getRealPath($xsdUrn);
$this->assertSame($xsdPath, $result, 'XSD paths does not match.');
}
示例8: getBlackList
/**
* @return array
*/
protected function getBlackList()
{
$blackListFiles = [];
$componentRegistrar = new ComponentRegistrar();
foreach ($this->getFilesData('blacklist/files_list*') as $fileInfo) {
$blackListFiles[] = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $fileInfo[0]) . DIRECTORY_SEPARATOR . $fileInfo[1];
}
return $blackListFiles;
}
示例9: execute
/**
* Download sample file action
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$fileName = $this->getRequest()->getParam('filename') . '.csv';
$moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::SAMPLE_FILES_MODULE);
$fileAbsolutePath = $moduleDir . '/Files/Sample/' . $fileName;
$directoryRead = $this->readFactory->create($moduleDir);
$filePath = $directoryRead->getRelativePath($fileAbsolutePath);
if (!$directoryRead->isFile($filePath)) {
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$this->messageManager->addError(__('There is no sample file for this entity.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/import');
return $resultRedirect;
}
$fileSize = isset($directoryRead->stat($filePath)['size']) ? $directoryRead->stat($filePath)['size'] : null;
$this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize);
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
$resultRaw->setContents($directoryRead->readFile($filePath));
return $resultRaw;
}
示例10: _getLocalePatternDir
/**
* Return pattern for theme locale directories, where <locale_placeholder> is placed to mark a locale's location.
*
* @param \Magento\Framework\View\Design\ThemeInterface $theme
* @return string
* @throws \Exception
*/
protected static function _getLocalePatternDir(\Magento\Framework\View\Design\ThemeInterface $theme)
{
$localePlaceholder = '<locale_placeholder>';
$params = ['area' => $theme->getArea(), 'theme' => $theme, 'locale' => $localePlaceholder];
$patternDirs = self::$_fallbackRule->getPatternDirs($params);
$themePath = self::$_componentRegistrar->getPath(\Magento\Framework\Component\ComponentRegistrar::THEME, $theme->getFullPath());
foreach ($patternDirs as $patternDir) {
$patternPath = $patternDir . '/';
if (strpos($patternPath, $themePath) !== false && strpos($patternPath, $localePlaceholder) !== false) {
return $patternDir;
}
}
throw new \Exception('Unable to determine theme locale path');
}
示例11: testLayoutFile
public function testLayoutFile()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(function ($layoutFile) {
$layoutXml = simplexml_load_file($layoutFile);
$this->_testObsoleteReferences($layoutXml);
$this->_testObsoleteAttributes($layoutXml);
$selectorHeadBlock = '(name()="block" or name()="referenceBlock") and ' . '(@name="head" or @name="convert_root_head" or @name="vde_head")';
$this->assertSame([], $layoutXml->xpath('//block[@class="Magento\\Theme\\Block\\Html\\Head\\Css" ' . 'or @class="Magento\\Theme\\Block\\Html\\Head\\Link" ' . 'or @class="Magento\\Theme\\Block\\Html\\Head\\Script"]' . '/parent::*[not(' . $selectorHeadBlock . ')]'), 'Blocks \\Magento\\Theme\\Block\\Html\\Head\\{Css,Link,Script} ' . 'are allowed within the "head" block only. ' . 'Verify integrity of the nodes nesting.');
$this->assertSame([], $layoutXml->xpath('/layout//*[@output="toHtml"]'), 'output="toHtml" is obsolete. Use output="1"');
foreach ($layoutXml as $handle) {
$this->assertNotContains((string) $handle['id'], $this->_obsoleteNodes, 'This layout handle is obsolete.');
}
foreach ($layoutXml->xpath('@helper') as $action) {
$this->assertNotContains('/', $action->getAttribute('helper'));
$this->assertContains('::', $action->getAttribute('helper'));
}
$componentRegistrar = new ComponentRegistrar();
if (false !== strpos($layoutFile, $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Sales') . '/view/adminhtml/layout/sales_order') || false !== strpos($layoutFile, $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Shipping') . '/view/adminhtml/layout/adminhtml_order')) {
$this->markTestIncomplete("The file {$layoutFile} has to use \\Magento\\Core\\Block\\Text\\List, \n" . 'there is no solution to get rid of it right now.');
}
$this->assertSame([], $layoutXml->xpath('/layout//block[@class="Magento\\Framework\\View\\Element\\Text\\ListText"]'), 'The class \\Magento\\Framework\\View\\Element\\Text\\ListTest' . ' is not supposed to be used in layout anymore.');
}, \Magento\Framework\App\Utility\Files::init()->getLayoutFiles());
}
示例12: buildPathToLocaleDirectoryByContext
/**
* Get paths by context
*
* @param string $type
* @param array $value
* @return string
* @throws \InvalidArgumentException
*/
public function buildPathToLocaleDirectoryByContext($type, $value)
{
switch ($type) {
case self::CONTEXT_TYPE_MODULE:
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $value);
break;
case self::CONTEXT_TYPE_THEME:
$path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $value);
break;
case self::CONTEXT_TYPE_LIB:
$path = BP . '/lib/web';
break;
default:
throw new \InvalidArgumentException(sprintf('Invalid context given: "%s".', $type));
}
return $path . '/' . self::LOCALE_DIRECTORY . '/';
}
示例13: prepareMenuConfig
/**
* @return \Magento\Backend\Model\Menu\Config
*/
protected function prepareMenuConfig()
{
$this->loginAdminUser();
$componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
$libraryPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework');
$reflection = new \ReflectionClass('Magento\\Framework\\Component\\ComponentRegistrar');
$paths = $reflection->getProperty('paths');
$paths->setAccessible(true);
$paths->setValue([ComponentRegistrar::MODULE => [], ComponentRegistrar::THEME => [], ComponentRegistrar::LANGUAGE => [], ComponentRegistrar::LIBRARY => []]);
$paths->setAccessible(false);
ComponentRegistrar::register(ComponentRegistrar::LIBRARY, 'magento/framework', $libraryPath);
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_Backend', __DIR__ . '/_files/menu/Magento/Backend');
/* @var $validationState \Magento\Framework\App\Arguments\ValidationState */
$validationState = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Arguments\\ValidationState', ['appMode' => State::MODE_DEFAULT]);
/* @var $configReader \Magento\Backend\Model\Menu\Config\Reader */
$configReader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Model\\Menu\\Config\\Reader', ['validationState' => $validationState]);
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Model\\Menu\\Config', ['configReader' => $configReader, 'configCacheType' => $this->configCacheType]);
}
示例14: get
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'global':
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
$themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
if ($themeConfigFile
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] =
$this->rootDirectory->readFile(
$this->rootDirectory->getRelativePath(
$themeConfigFile
)
);
} else {
$designPath =
$this->componentRegistrar->getPath(
ComponentRegistrar::THEME,
$this->area . '/' . $this->themePath
) . '/etc/view.xml';
if (file_exists($designPath)) {
try {
$designDom = new \DOMDocument;
$designDom->load($designPath);
$iterator[$designPath] = $designDom->saveXML();
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Could not read config file')
);
}
}
}
break;
default:
$iterator = $this->iteratorFactory->create([]);
break;
}
return $iterator;
}
示例15: _extractWhitelist
/**
* Extract whitelisted entries and words from configuration xml
*
* @param \SimpleXMLElement $configXml
* @return \Magento\TestFramework\Inspection\WordsFinder
* @throws \Magento\TestFramework\Inspection\Exception
*/
protected function _extractWhitelist(\SimpleXMLElement $configXml)
{
// Load whitelist entries
$whitelist = [];
$nodes = $configXml->xpath('//config/whitelist/item');
foreach ($nodes as $node) {
$path = $node->xpath('path');
if (!$path) {
throw new \Magento\TestFramework\Inspection\Exception('A "path" must be defined for the whitelisted item');
}
$component = $node->xpath('component');
if ($component) {
$componentType = $component[0]->xpath('@type')[0];
$componentName = $component[0]->xpath('@name')[0];
$path = $this->componentRegistrar->getPath((string) $componentType, (string) $componentName) . '/' . (string) $path[0];
} else {
$path = $this->_baseDir . '/' . (string) $path[0];
}
// Words
$words = [];
$wordNodes = $node->xpath('word');
if ($wordNodes) {
foreach ($wordNodes as $wordNode) {
$words[] = (string) $wordNode;
}
}
$whitelist[$path] = $words;
}
// Merge with already present whitelist
foreach ($whitelist as $newPath => $newWords) {
if (isset($this->_whitelist[$newPath])) {
$newWords = array_merge($this->_whitelist[$newPath], $newWords);
}
$this->_whitelist[$newPath] = array_unique($newWords);
}
return $this;
}