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)); }
/** * 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; }
public function testRouteConfigsValidation() { $invalidFiles = []; $componentRegistrar = new ComponentRegistrar(); $files = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $mask = $moduleDir . '/etc/*/routes.xml'; $files = array_merge($files, glob($mask)); } $mergedConfig = new \Magento\Framework\Config\Dom('<config></config>', $this->_idAttributes); foreach ($files as $file) { $content = file_get_contents($file); try { new \Magento\Framework\Config\Dom($content, $this->_idAttributes, null, $this->schemaFile); //merge won't be performed if file is invalid because of exception thrown $mergedConfig->merge($content); } catch (\Magento\Framework\Config\Dom\ValidationException $e) { $invalidFiles[] = $file; } } if (!empty($invalidFiles)) { $this->fail('Found broken files: ' . implode("\n", $invalidFiles)); } try { $errors = []; $mergedConfig->validate($this->mergedSchemaFile, $errors); } catch (\Exception $e) { $this->fail('Merged routes config is invalid: ' . "\n" . implode("\n", $errors)); } }
/** * Test circular dependencies between languages */ public function testCircularDependencies() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $componentRegistrar = new ComponentRegistrar(); $declaredLanguages = $componentRegistrar->getPaths(ComponentRegistrar::LANGUAGE); $validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false); $validationStateMock->method('isValidationRequired')->willReturn(true); $domFactoryMock = $this->getMock('Magento\\Framework\\Config\\DomFactory', [], [], '', false); $domFactoryMock->expects($this->any())->method('createDom')->willReturnCallback(function ($arguments) use($validationStateMock) { return new \Magento\Framework\Config\Dom($arguments['xml'], $validationStateMock, [], null, $arguments['schemaFile']); }); $packs = []; foreach ($declaredLanguages as $language) { $languageConfig = $objectManager->getObject('Magento\\Framework\\App\\Language\\Config', ['source' => file_get_contents($language . '/language.xml'), 'domFactory' => $domFactoryMock]); $this->packs[$languageConfig->getVendor()][$languageConfig->getPackage()] = $languageConfig; $packs[] = $languageConfig; } /** @var $languageConfig Config */ foreach ($packs as $languageConfig) { $languages = []; /** @var $config Config */ foreach ($this->collectCircularInheritance($languageConfig) as $config) { $languages[] = $config->getVendor() . '/' . $config->getPackage(); } if (!empty($languages)) { $this->fail("Circular dependency detected:\n" . implode(' -> ', $languages)); } } }
/** * @expectedException \Zend_Json_Exception */ public function testGetPackageNameInvalidJson() { $this->componentRegistrar->expects($this->once())->method('getPath')->willReturn('path/to/A'); $this->dirRead->expects($this->once())->method('isExist')->willReturn(true); $this->dirRead->expects($this->once())->method('readFile')->willReturn('{"name": }'); $this->themePackageInfo->getPackageName('themeA'); }
/** * @return \RegexIterator */ protected function _getFiles() { $filesCollector = new FilesCollector(); $componentRegistrar = new ComponentRegistrar(); $paths = array_merge($componentRegistrar->getPaths(ComponentRegistrar::MODULE), $componentRegistrar->getPaths(ComponentRegistrar::LIBRARY)); return $filesCollector->getFiles($paths, '/\\.(php|phtml)$/'); }
/** * 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; }
public function testLocalXmlFilesAbsent() { $componentRegistrar = new ComponentRegistrar(); foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themeDir) { $this->assertEmpty(glob($themeDir . '/local.xml')); } }
/** * Class constructor * * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface * @param ComponentRegistrar $componentRegistrar * @param string|null $scope */ public function __construct(\Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface, ComponentRegistrar $componentRegistrar, $scope = null) { $this->_filesystem = $filesystem; $this->_isAllowSymlinks = $scopeConfigInterface->getValue(self::XML_PATH_TEMPLATE_ALLOW_SYMLINK, $scope); $this->_themesDir = $componentRegistrar->getPaths(ComponentRegistrar::THEME); $this->moduleDirs = $componentRegistrar->getPaths(ComponentRegistrar::MODULE); $this->_compiledDir = $this->_filesystem->getDirectoryRead(DirectoryList::TEMPLATE_MINIFICATION_DIR)->getAbsolutePath(); }
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.'); }
/** * @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; }
public function setUp() { $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $objectManagerProvider = $this->getMock( 'Magento\Setup\Model\ObjectManagerProvider', [], [], '', false ); $this->objectManager = $this->getMockForAbstractClass( 'Magento\Framework\ObjectManagerInterface', [], '', false ); $this->cacheMock = $this->getMockBuilder('Magento\Framework\App\Cache') ->disableOriginalConstructor() ->getMock(); $objectManagerProvider->expects($this->once()) ->method('get') ->willReturn($this->objectManager); $this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false); $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); $this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem') ->disableOriginalConstructor() ->getMock(); $this->fileDriver = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File') ->disableOriginalConstructor() ->getMock(); $this->componentRegistrar = $this->getMock( '\Magento\Framework\Component\ComponentRegistrar', [], [], '', false ); $this->componentRegistrar->expects($this->any())->method('getPaths')->willReturnMap([ [ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']], [ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']], ]); $this->command = new DiCompileCommand( $this->deploymentConfig, $this->directoryList, $this->manager, $objectManagerProvider, $this->filesystem, $this->fileDriver, $this->componentRegistrar ); }
public function setUp() { $this->componentRegistrar = $this->getMock('Magento\\Framework\\Component\\ComponentRegistrar', [], [], '', false); $this->reader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', [], [], '', false); $this->componentRegistrar->expects($this->once())->method('getPaths')->will($this->returnValue(['A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E'])); $composerData = ['A/composer.json' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', 'B/composer.json' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}', 'C/composer.json' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', 'D/composer.json' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}', 'E/composer.json' => '{"name":"e", "version":"0.4"}']; $fileIteratorMock = $this->getMock('Magento\\Framework\\Config\\FileIterator', [], [], '', false); $fileIteratorMock->expects($this->once())->method('toArray')->will($this->returnValue($composerData)); $this->reader->expects($this->once())->method('getComposerJsonFiles')->will($this->returnValue($fileIteratorMock)); $this->packageInfo = new PackageInfo($this->reader, $this->componentRegistrar); }
/** * Test Setup * * @return void */ public function setUp() { $this->_fileSystemMock = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false); $this->_scopeConfigMock = $this->getMock('\\Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $this->rootDirectoryMock = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->compiledDirectoryMock = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->_fileSystemMock->expects($this->any())->method('getDirectoryRead')->will($this->returnValueMap([[DirectoryList::ROOT, DriverPool::FILE, $this->rootDirectoryMock], [DirectoryList::TEMPLATE_MINIFICATION_DIR, DriverPool::FILE, $this->compiledDirectoryMock]])); $this->compiledDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnValue('/magento/var/compiled')); $this->componentRegistrar = $this->getMock('Magento\\Framework\\Component\\ComponentRegistrar', [], [], '', false); $this->componentRegistrar->expects($this->any())->method('getPaths')->will($this->returnValueMap([[ComponentRegistrar::MODULE, ['/magento/app/code/Some/Module']], [ComponentRegistrar::THEME, ['/magento/themes/default']]])); $this->_validator = new \Magento\Framework\View\Element\Template\File\Validator($this->_fileSystemMock, $this->_scopeConfigMock, $this->componentRegistrar); }
/** * Initialize package name to full theme path map * * @return void * @throws \Zend_Json_Exception */ private function initializeMap() { $themePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::THEME); /** @var \Magento\Theme\Model\Theme $theme */ foreach ($themePaths as $fullThemePath => $themeDir) { $themeDirRead = $this->readDirFactory->create($themeDir); if ($themeDirRead->isExist('composer.json')) { $rawData = \Zend_Json::decode($themeDirRead->readFile('composer.json')); if (isset($rawData['name'])) { $this->packageNameToFullPathMap[$rawData['name']] = $fullThemePath; } } } }
/** * @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(); }
/** * Retrieve suggested sample data packages from modules composer.json * * @return array */ protected function getSuggestsFromModules() { $suggests = []; foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $file = $moduleDir . '/composer.json'; /** @var Package $package */ $package = $this->getModuleComposerPackage($file); $suggest = json_decode(json_encode($package->get('suggest')), true); if (!empty($suggest)) { $suggests += $suggest; } } return $suggests; }
public function setUp() { $componentRegistrar = new ComponentRegistrar(); $dirSearch = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Component\\DirSearch'); $themePackageList = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\Theme\\ThemePackageList'); $this->model = new Files($componentRegistrar, $dirSearch, $themePackageList); foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $this->moduleTests[] = '#' . $moduleDir . '/Test#'; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryDir) { $this->libTests[] = '#' . $libraryDir . '/Test#'; $this->frameworkTests[] = '#' . $libraryDir . '/[\\w]+/Test#'; } }
/** * @return array */ public function getLocalePlacePath() { $pathToSource = BP; $places = []; $componentRegistrar = new ComponentRegistrar(); foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) { $places[basename($modulePath)] = ['placePath' => $modulePath]; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themePath) { $placeName = basename(dirname(dirname($themePath))) . '_' . basename($themePath); $places[$placeName] = ['placePath' => $themePath]; } $places['lib_web'] = ['placePath' => "{$pathToSource}/lib/web"]; return $places; }
/** * Constructor */ public function __construct() { $componentRegistrar = new ComponentRegistrar(); /** @var \Magento\Framework\Filesystem $filesystem */ foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $key = $moduleDir . '/'; $value = $key . 'Test/Unit/'; self::$_cleanableFolders[$key] = [$value]; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryDir) { $key = $libraryDir . '/'; $valueRootFolder = $key . '/Test/Unit/'; $valueSubFolder = $key . '/*/Test/Unit/'; self::$_cleanableFolders[$key] = [$valueSubFolder, $valueRootFolder]; } }
/** * 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]; }
/** * Get the given type component directories * * @param string $componentType * @return array */ private function getComponentDirectories($componentType) { $dirs = []; foreach ($this->componentRegistrar->getPaths($componentType) as $componentDir) { $dirs[] = $componentDir . '/'; } return $dirs; }
public function getXmlFiles() { $componentRegistrar = new ComponentRegistrar(); $codeXml = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $modulePath) { $codeXml = array_merge($codeXml, $this->_getFiles($modulePath, '*.xml', '/.\\/Test\\/Unit\\/./')); } $this->_filterSpecialCases($codeXml); $designXml = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themePath) { $designXml = array_merge($designXml, $this->_getFiles($themePath, '*.xml')); } $libXml = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $libraryPath) { $libXml = array_merge($libXml, $this->_getFiles($libraryPath, '*.xml', '/.\\/Test\\/./')); } return $this->_dataSet(array_merge($codeXml, $designXml, $libXml)); }
/** * @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]); }
public function testForOldInstallUpgradeScripts() { $scriptPattern = []; $componentRegistrar = new ComponentRegistrar(); foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $scriptPattern[] = $moduleDir . '/sql'; $scriptPattern[] = $moduleDir . '/data'; } $invoker = new AggregateInvoker($this); $invoker(function ($file) { $this->assertStringStartsNotWith('install-', basename($file), 'Install scripts are obsolete. Please create class InstallSchema in module\'s Setup folder'); $this->assertStringStartsNotWith('data-install-', basename($file), 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder'); $this->assertStringStartsNotWith('upgrade-', basename($file), 'Upgrade scripts are obsolete. Please create class UpgradeSchema in module\'s Setup folder'); $this->assertStringStartsNotWith('data-upgrade-', basename($file), 'Upgrade scripts are obsolete. Please create class UpgradeData in module\'s Setup folder'); $this->assertStringStartsNotWith('recurring', basename($file), 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder'); $this->fail('Invalid directory. Please convert data/sql scripts to a class within module\'s Setup folder'); }, $this->convertArray(Files::init()->getFiles($scriptPattern, '*.php'))); }
public function testGeneration() { $this->assertFileNotExists($this->_packPath); ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_FirstModule', $this->_packPath . '/app/code/Magento/FirstModule'); ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_SecondModule', $this->_packPath . '/app/code/Magento/SecondModule'); ComponentRegistrar::register(ComponentRegistrar::THEME, 'adminhtml/default', $this->_packPath . '/app/design/adminhtml/default'); $this->_generator->generate($this->_dictionaryPath, $this->_locale); foreach ($this->_expectedFiles as $file) { $this->assertFileEquals($this->_expectedDir . $file, $this->_packPath . $file); } }
/** * @return array */ public function validateComposerJsonDataProvider() { $root = \Magento\Framework\App\Utility\Files::init()->getPathToSource(); $componentRegistrar = new ComponentRegistrar(); $result = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $dir) { $result[$dir] = [$dir, 'magento2-module']; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::LANGUAGE) as $dir) { $result[$dir] = [$dir, 'magento2-language']; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $dir) { $result[$dir] = [$dir, 'magento2-theme']; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $dir) { $result[$dir] = [$dir, 'magento2-library']; } $result[$root] = [$root, 'project']; return $result; }
public function testObsoleteViewPaths() { $allowedFiles = ['requirejs-config.js', 'layouts.xml']; $allowedThemeFiles = array_merge($allowedFiles, ['composer.json', 'theme.xml', 'LICENSE.txt', 'LICENSE_EE.txt', 'LICENSE_AFL.txt', 'registration.php']); $areas = '{frontend,adminhtml,base}'; $componentRegistrar = new ComponentRegistrar(); $pathsToCheck = []; foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $themeDir) { $pathsToCheck[$themeDir . '/*'] = ['allowed_files' => $allowedThemeFiles, 'allowed_dirs' => ['layout', 'page_layout', 'templates', 'web', 'etc', 'i18n', 'media', '\\w+_\\w+']]; $pathsToCheck[$themeDir . '/*_*/*'] = ['allowed_files' => $allowedThemeFiles, 'allowed_dirs' => ['layout', 'page_layout', 'templates', 'web', 'email']]; } foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) { $pathsToCheck[$moduleDir . "/view/{$areas}/*"] = ['allowed_files' => $allowedFiles, 'allowed_dirs' => ['layout', 'page_layout', 'templates', 'web', 'ui_component', 'email']]; } $errors = []; foreach ($pathsToCheck as $path => $allowed) { $allowedFiles = $allowed['allowed_files']; $allowedDirs = $allowed['allowed_dirs']; $foundFiles = glob($path, GLOB_BRACE); if (!$foundFiles) { continue; } foreach ($foundFiles as $file) { $baseName = basename($file); if (is_dir($file)) { foreach ($allowedDirs as $allowedDir) { if (preg_match("#^{$allowedDir}\$#", $baseName)) { continue 2; } } } if (in_array($baseName, $allowedFiles)) { continue; } $errors[] = $file; } } if (!empty($errors)) { $this->fail('Unexpected files or directories found. Make sure they are not at obsolete locations:' . PHP_EOL . implode(PHP_EOL, $errors)); } }
/** * 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; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $errors = $this->checkEnvironment(); if ($errors) { foreach ($errors as $line) { $output->writeln($line); } // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } $modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE); $libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY); $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION); $this->objectManager->get('Magento\\Framework\\App\\Cache')->clean(); $compiledPathsList = ['application' => $modulePaths, 'library' => $libraryPaths, 'generated_helpers' => $generationPath]; $excludedModulePaths = []; foreach ($modulePaths as $appCodePath) { $excludedModulePaths[] = '#^' . $appCodePath . '/Test#'; } $excludedLibraryPaths = []; foreach ($libraryPaths as $libraryPath) { $excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#'; } $this->excludedPathsList = ['application' => $excludedModulePaths, 'framework' => $excludedLibraryPaths]; $this->configureObjectManager($output); $operations = $this->getOperationsConfiguration($compiledPathsList); try { $this->cleanupFilesystem([DirectoryList::CACHE, DirectoryList::DI]); foreach ($operations as $operationCode => $arguments) { $this->taskManager->addOperation($operationCode, $arguments); } /** @var ProgressBar $progressBar */ $progressBar = $this->objectManager->create('Symfony\\Component\\Console\\Helper\\ProgressBar', ['output' => $output, 'max' => count($operations)]); $progressBar->setFormat('<info>%message%</info> %current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%'); $output->writeln('<info>Compilation was started.</info>'); $progressBar->start(); $progressBar->display(); $this->taskManager->process(function (OperationInterface $operation) use($progressBar) { $progressBar->setMessage($operation->getName() . '...'); $progressBar->display(); }, function (OperationInterface $operation) use($progressBar) { $progressBar->advance(); }); $progressBar->finish(); $output->writeln(''); $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>'); } catch (OperationException $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); // we must have an exit code higher than zero to indicate something was wrong return \Magento\Framework\Console\Cli::RETURN_FAILURE; } }