本文整理汇总了PHP中Magento\Framework\App\Utility\Files类的典型用法代码示例。如果您正苦于以下问题:PHP Files类的具体用法?PHP Files怎么用?PHP Files使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Files类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrnDictionary
/**
* Get an array of URNs
*
* @param OutputInterface $output
* @return array
*/
private function getUrnDictionary(OutputInterface $output)
{
$files = $this->filesUtility->getXmlCatalogFiles('*.xml');
$files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd'));
$urns = [];
foreach ($files as $file) {
$content = $this->rootDirRead->readFile($this->rootDirRead->getRelativePath($file[0]));
$matches = [];
preg_match_all('/schemaLocation="(urn\\:magento\\:[^"]*)"/i', $content, $matches);
if (isset($matches[1])) {
$urns = array_merge($urns, $matches[1]);
}
}
$urns = array_unique($urns);
$paths = [];
foreach ($urns as $urn) {
try {
$paths[$urn] = $this->urnResolver->getRealPath($urn);
} catch (\Exception $e) {
// don't add unsupported element to array
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($e->getMessage());
}
}
}
return $paths;
}
示例2: testGetClassFilesOnlyTests
public function testGetClassFilesOnlyTests()
{
$classFiles = $this->model->getClassFiles(false, true, false, false, false);
$classFiles = preg_grep($this->moduleTests, $classFiles, PREG_GREP_INVERT);
$classFiles = preg_grep($this->libTests, $classFiles, PREG_GREP_INVERT);
$classFiles = preg_grep($this->frameworkTests, $classFiles, PREG_GREP_INVERT);
$classFiles = preg_grep($this->toolsTests, $classFiles, PREG_GREP_INVERT);
$classFiles = preg_grep($this->rootTestsDir, $classFiles, PREG_GREP_INVERT);
$classFiles = preg_grep($this->setupTestsDir, $classFiles, PREG_GREP_INVERT);
$this->assertEmpty($classFiles);
}
示例3: getData
/**
* Get translation data
*
* @param string $themePath
* @return string[]
* @throws \Exception
* @throws \Magento\Framework\Exception
*/
public function getData($themePath)
{
$dictionary = [];
$files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath);
foreach ($files as $filePath) {
$content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0]));
foreach ($this->getPhrases($content) as $phrase) {
$translatedPhrase = (string) __($phrase);
if ($phrase != $translatedPhrase) {
$dictionary[$phrase] = $translatedPhrase;
}
}
}
return $dictionary;
}
示例4: testGetData
/**
* @return void
*/
public function testGetData()
{
$themePath = 'blank';
$areaCode = 'adminhtml';
$files = [['path1'], ['path2']];
$relativePathMap = [['path1' => 'relativePath1'], ['path2' => 'relativePath2']];
$contentsMap = [['relativePath1' => 'content1$.mage.__("hello1")content1'], ['relativePath2' => 'content2$.mage.__("hello2")content2']];
$patterns = ['~\\$\\.mage\\.__\\([\'|\\"](.+?)[\'|\\"]\\)~'];
$this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
$this->filesUtilityMock->expects($this->once())->method('getJsFiles')->with($areaCode, $themePath)->willReturn($files);
$this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnMap($relativePathMap);
$this->rootDirectoryMock->expects($this->any())->method('readFile')->willReturnMap($contentsMap);
$this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
$this->assertEquals([], $this->model->getData($themePath));
}
示例5: getDependencyInfo
/**
* Gets alien dependencies information for current module by analyzing file's contents
*
* @param string $currentModule
* @param string $fileType
* @param string $file
* @param string $contents
* @return array
*/
public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
{
if (!in_array($fileType, ['php', 'template'])) {
return [];
}
$pattern = '~\\b(?<class>(?<module>(' . implode('_|', \Magento\Framework\App\Utility\Files::init()->getNamespaces()) . '[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\\b~';
$dependenciesInfo = [];
if (preg_match_all($pattern, $contents, $matches)) {
$matches['module'] = array_unique($matches['module']);
foreach ($matches['module'] as $i => $referenceModule) {
$referenceModule = str_replace('_', '\\', $referenceModule);
if ($currentModule == $referenceModule) {
continue;
}
$dependenciesInfo[] = ['module' => $referenceModule, 'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD, 'source' => trim($matches['class'][$i])];
}
}
$result = $this->_caseGetUrl($currentModule, $contents);
if (count($result)) {
$dependenciesInfo = array_merge($dependenciesInfo, $result);
}
$result = $this->_caseLayoutBlock($currentModule, $fileType, $file, $contents);
if (count($result)) {
$dependenciesInfo = array_merge($dependenciesInfo, $result);
}
return $dependenciesInfo;
}
示例6: testLocalXmlFilesAbsent
public function testLocalXmlFilesAbsent()
{
$area = '*';
$package = '*';
$theme = '*';
$this->assertEmpty(glob(\Magento\Framework\App\Utility\Files::init()->getPathToSource() . "/app/design/{$area}/{$package}/{$theme}/local.xml"));
}
示例7: getWhitelist
/**
* Returns whitelist based on blacklist and git changed files
*
* @param array $fileTypes
* @param string $changedFilesBaseDir
* @param string $baseFilesFolder
* @return array
*/
public static function getWhitelist($fileTypes = ['php'], $changedFilesBaseDir = '', $baseFilesFolder = '')
{
$globPatternsFolder = self::getBaseFilesFolder();
if ('' !== $baseFilesFolder) {
$globPatternsFolder = $baseFilesFolder;
}
$directoriesToCheck = Files::init()->readLists($globPatternsFolder . '/_files/whitelist/common.txt');
$changedFiles = [];
$globFilesListPattern = ($changedFilesBaseDir ?: self::getChangedFilesBaseDir()) . '/_files/changed_files*';
foreach (glob($globFilesListPattern) as $listFile) {
$changedFiles = array_merge($changedFiles, file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
}
array_walk($changedFiles, function (&$file) {
$file = BP . '/' . $file;
});
$changedFiles = array_filter($changedFiles, function ($path) use($directoriesToCheck, $fileTypes) {
if (!file_exists($path)) {
return false;
}
$path = realpath($path);
foreach ($directoriesToCheck as $directory) {
$directory = realpath($directory);
if (strpos($path, $directory) === 0) {
if (!empty($fileTypes)) {
return in_array(pathinfo($path, PATHINFO_EXTENSION), $fileTypes);
}
return true;
}
}
return false;
});
return $changedFiles;
}
示例8: testReadListsCorruptedFile
public function testReadListsCorruptedFile()
{
$result = Files::init()->readLists(__DIR__ . '/_files/list_corrupted_file.txt');
foreach ($result as $path) {
$this->assertNotContains('unknown.txt', $path);
}
}
示例9: buildReport
/**
* Build Framework dependencies report
*
* @param string $outputPath
* @return void
*/
protected function buildReport($outputPath)
{
$filePaths = $this->registrar->getPaths(ComponentRegistrar::MODULE);
$filesForParse = Files::init()->getFiles($filePaths, '*');
$configFiles = Files::init()->getConfigFiles('module.xml', [], false);
ServiceLocator::getFrameworkDependenciesReportBuilder()->build(['parse' => ['files_for_parse' => $filesForParse, 'config_files' => $configFiles, 'declared_namespaces' => Files::init()->getNamespaces()], 'write' => ['report_filename' => $outputPath]]);
}
示例10: collectAppFiles
/**
* Accumulate all static view files in the application and record all found areas, themes and languages
*
* Returns an array of areas and files with meta information
*
* @param array $requestedLocales
* @return array
*/
private function collectAppFiles($requestedLocales)
{
$areas = [];
$locales = [];
$files = $this->filesUtil->getStaticPreProcessingFiles();
foreach ($files as $info) {
list($area, $themePath, $locale) = $info;
if ($themePath) {
$areas[$area][$themePath] = $themePath;
}
if ($locale) {
$locales[$locale] = $locale;
}
}
foreach ($requestedLocales as $locale) {
unset($locales[$locale]);
}
if (!empty($locales)) {
$langList = implode(', ', $locales);
$this->output->writeln(
"WARNING: there were files for the following languages detected in the file system: {$langList}."
. ' These languages were not requested, so the files will not be populated.'
);
}
return [$areas, $files];
}
示例11: __construct
/**
* Constructor
*
* @param array $mapRouters
* @param array $mapLayoutBlocks
* @param array $mapLayoutHandles
*/
public function __construct(array $mapRouters, array $mapLayoutBlocks, array $mapLayoutHandles)
{
$this->_mapRouters = $mapRouters;
$this->_mapLayoutBlocks = $mapLayoutBlocks;
$this->_mapLayoutHandles = $mapLayoutHandles;
$this->_namespaces = implode('|', \Magento\Framework\App\Utility\Files::init()->getNamespaces());
}
示例12: testObsoleteDirectives
public function testObsoleteDirectives()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(function ($file) {
$this->assertNotRegExp('/\\{\\{htmlescape.*?\\}\\}/i', file_get_contents($file), 'Directive {{htmlescape}} is obsolete. Use {{escapehtml}} instead.');
}, \Magento\Framework\App\Utility\Files::init()->getEmailTemplates());
}
示例13: testObsoleteJavascriptAttributeType
public function testObsoleteJavascriptAttributeType()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(function ($file) {
$this->assertNotRegexp('/type="text\\/javascript"/', file_get_contents($file), 'Please do not use "text/javascript" type attribute.');
}, \Magento\Framework\App\Utility\Files::init()->getPhtmlFiles());
}
示例14: setupFileLists
/**
* Helper method to setup the black and white lists
*
* @param string $type
* @return void
*/
public static function setupFileLists($type = '')
{
if ($type != '' && !preg_match('/\\/$/', $type)) {
$type = $type . '/';
}
self::$whiteList = Files::readLists(__DIR__ . '/_files/' . $type . 'whitelist/*.txt');
self::$blackList = Files::readLists(__DIR__ . '/_files/' . $type . 'blacklist/*.txt');
}
示例15: _getBaseFrontendHandles
/**
* Return layout handles that are declared in the base layouts for frontend
*
* @return array
*/
protected function _getBaseFrontendHandles()
{
if ($this->_baseFrontendHandles === null) {
$files = \Magento\Framework\App\Utility\Files::init()->getLayoutFiles(['include_design' => false, 'area' => 'frontend'], false);
$this->_baseFrontendHandles = $this->_extractLayoutHandles($files);
}
return $this->_baseFrontendHandles;
}