本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\ReadInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ReadInterface类的具体用法?PHP ReadInterface怎么用?PHP ReadInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReadInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFiles
/**
* @param ReadInterface $reader
* @param ThemeInterface $theme
* @param array $files
* @return array
*/
protected function createFiles(ReadInterface $reader, ThemeInterface $theme, $files)
{
$result = [];
foreach ($files as $file) {
$filename = $reader->getAbsolutePath($file);
$result[] = $this->fileFactory->create($filename, false, $theme);
}
return $result;
}
示例2: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return array|\Magento\Framework\View\File[]
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$result = [];
$namespace = $module = '*';
$sharedFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/base/{$this->subDir}{$filePath}");
$filePathPtn = strtr(preg_quote($filePath), ['\\*' => '[^/]+']);
$pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/base/{$this->subDir}" . $filePathPtn . "\$#i";
foreach ($sharedFiles as $file) {
$filename = $this->modulesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = "{$matches['namespace']}_{$matches['module']}";
$result[] = $this->fileFactory->create($filename, $moduleFull, null, true);
}
$area = $theme->getData('area');
$themeFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/{$area}/{$this->subDir}{$filePath}");
$pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/{$area}/{$this->subDir}" . $filePathPtn . "\$#i";
foreach ($themeFiles as $file) {
$filename = $this->modulesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = "{$matches['namespace']}_{$matches['module']}";
$result[] = $this->fileFactory->create($filename, $moduleFull);
}
return $result;
}
示例3: 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;
}
示例4: testLoadData
/**
* @test
* @return void
*/
public function testLoadData()
{
$fileContent = 'content file';
$media = ['preview_image' => 'preview.jpg'];
$themeTitle = 'Theme title';
$themeConfigFile = 'theme.xml';
$themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
$theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
$parentTheme = ['parentThemeCode'];
$parentThemePath = 'frontend/parent/theme';
$themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
$themePackage->expects($this->any())->method('getArea')->will($this->returnValue('frontend'));
$themePackage->expects($this->any())->method('getVendor')->will($this->returnValue('theme'));
$themePackage->expects($this->any())->method('getName')->will($this->returnValue('code'));
$this->themePackageList->expects($this->once())->method('getThemes')->will($this->returnValue([$themePackage]));
$this->directory->expects($this->once())->method('isExist')->with($themeConfigFile)->willReturn(true);
$this->directory->expects($this->once())->method('readFile')->with($themeConfigFile)->willReturn($fileContent);
$this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
$this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
$themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
$themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
$themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
$theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme/code', 'code' => 'theme/code', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => 'theme/parentThemeCode'])->willReturnSelf();
$theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
$theme->expects($this->once())->method('getArea')->willReturn('frontend');
$this->assertInstanceOf(get_class($this->model), $this->model->loadData());
}
示例5: current
/**
* Current
*
* @return string
*/
public function current()
{
if (!isset($this->cached[$this->key()])) {
$this->cached[$this->key()] = $this->directoryRead->readFile($this->key());
}
return $this->cached[$this->key()];
}
示例6: testGetConfig
public function testGetConfig()
{
$this->baseDir->expects($this->any())->method('getRelativePath')->will($this->returnCallback(function ($path) {
return 'relative/' . $path;
}));
$this->baseDir->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) {
return $file . ' content';
}));
$fileOne = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false);
$fileOne->expects($this->once())->method('getFilename')->will($this->returnValue('file_one.js'));
$fileOne->expects($this->once())->method('getModule')->will($this->returnValue('Module_One'));
$fileTwo = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false);
$fileTwo->expects($this->once())->method('getFilename')->will($this->returnValue('file_two.js'));
$theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface');
$this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme));
$this->fileSource->expects($this->once())->method('getFiles')->with($theme, Config::CONFIG_FILE_NAME)->will($this->returnValue([$fileOne, $fileTwo]));
$expected = <<<expected
(function(require){
require.config({"baseUrl":""});
(function() {
relative/file_one.js content
require.config(config);
})();
(function() {
relative/file_two.js content
require.config(config);
})();
})(require);
expected;
$actual = $this->object->getConfig();
$this->assertStringMatchesFormat($expected, $actual);
}
示例7: getContents
/**
* Returns contents of License file.
*
* @return string
*/
public function getContents()
{
if (!$this->dir->isFile(self::LICENSE_FILENAME)) {
return false;
}
return $this->dir->readFile(self::LICENSE_FILENAME);
}
示例8: testLoadData
/**
* @param string $area
* @param bool $forceReload
* @param array $cachedData
* @dataProvider dataProviderForTestLoadData
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function testLoadData($area, $forceReload, $cachedData)
{
$this->expectsSetConfig('themeId');
$this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('load')->will($this->returnValue(serialize($cachedData)));
if (!$forceReload && $cachedData !== false) {
$this->translate->loadData($area, $forceReload);
$this->assertEquals($cachedData, $this->translate->getData());
return;
}
$this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true));
// _loadModuleTranslation()
$this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name']));
$moduleData = ['module original' => 'module translated', 'module theme' => 'module-theme original translated', 'module pack' => 'module-pack original translated', 'module db' => 'module-db original translated'];
$this->modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module'));
$themeData = ['theme original' => 'theme translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'theme-pack translated overwrite', 'module db' => 'theme-db translated overwrite'];
$this->csvParser->expects($this->any())->method('getDataPairs')->will($this->returnValueMap([['/app/module/en_US.csv', 0, 1, $moduleData], ['/app/module/en_GB.csv', 0, 1, $moduleData], ['/theme.csv', 0, 1, $themeData]]));
// _loadThemeTranslation()
$this->viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue('/theme.csv'));
// _loadPackTranslation
$packData = ['pack original' => 'pack translated', 'module pack' => 'pack translated overwrite', 'module db' => 'pack-db translated overwrite'];
$this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData));
// _loadDbTranslation()
$dbData = ['db original' => 'db translated', 'module db' => 'db translated overwrite'];
$this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData));
$this->cache->expects($this->exactly(1))->method('save');
$this->translate->loadData($area, $forceReload);
$expected = ['module original' => 'module translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'pack translated overwrite', 'module db' => 'db translated overwrite', 'theme original' => 'theme translated', 'pack original' => 'pack translated', 'db original' => 'db translated'];
$this->assertEquals($expected, $this->translate->getData());
}
示例9: getFiles
/**
* Retrieve files
*
* @param ThemeInterface $theme
* @param string $filePath
* @return array|\Magento\Framework\View\File[]
* @throws \Magento\Framework\Exception
*/
public function getFiles(ThemeInterface $theme, $filePath)
{
$namespace = $module = '*';
$themePath = $theme->getFullPath();
$searchPattern = "{$themePath}/{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}";
$files = $this->themesDirectory->search($searchPattern);
if (empty($files)) {
return [];
}
$themes = [];
$currentTheme = $theme;
while ($currentTheme = $currentTheme->getParentTheme()) {
$themes[$currentTheme->getCode()] = $currentTheme;
}
$result = [];
$pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . strtr(preg_quote($filePath), ['\\*' => '[^/]+']) . "\$#i";
foreach ($files as $file) {
$filename = $this->themesDirectory->getAbsolutePath($file);
if (!preg_match($pattern, $filename, $matches)) {
continue;
}
$moduleFull = $matches['module'];
$ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName'];
if (!isset($themes[$ancestorThemeCode])) {
throw new Exception(sprintf("Trying to override modular view file '%s' for theme '%s', which is not ancestor of theme '%s'", $filename, $ancestorThemeCode, $theme->getCode()));
}
$result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]);
}
return $result;
}
示例10: testPublish
public function testPublish()
{
$this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
$materializationStrategy = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\StrategyInterface', [], [], '', false);
$this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy));
$materializationStrategy->expects($this->once())->method('publishFile')->with($this->sourceDirWrite, $this->staticDirWrite, 'file.ext', 'some/file.ext')->will($this->returnValue(true));
$this->assertTrue($this->object->publish($this->getAsset()));
}
示例11: testPublish
public function testPublish()
{
$this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
$this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
$this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
$this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true));
$this->assertTrue($this->object->publish($this->getAsset()));
}
示例12: get
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function get($filename, $scope)
{
$configPaths = $this->configDirectory->search('{*' . $filename . ',*/*' . $filename . '}');
$configAbsolutePaths = [];
foreach ($configPaths as $configPath) {
$configAbsolutePaths[] = $this->configDirectory->getAbsolutePath($configPath);
}
return $this->iteratorFactory->create($configAbsolutePaths);
}
示例13: minify
/**
* Minify template file
*
* @param string $file
* @return void
*/
public function minify($file)
{
$file = $this->rootDirectory->getRelativePath($file);
$content = preg_replace('#(?<!]]>)\\s+</#', '</', preg_replace('#((?:<\\?php\\s+(?!echo|print|if|elseif|else)[^\\?]*)\\?>)\\s+#', '$1 ', preg_replace('#(?<!' . implode('|', $this->inlineHtmlTags) . ')\\> \\<#', '><', preg_replace('#(?ix)(?>[^\\S ]\\s*|\\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\\b))*+)' . '(?:<(?>textarea|pre|script)\\b|\\z))#', ' ', preg_replace('#(?<!:|\\\\|\'|")//(?!\\s*\\<\\!\\[)(?!\\s*]]\\>)[^\\n\\r]*#', '', preg_replace('#(?<!:)//[^\\n\\r]*(\\s\\?\\>)#', '$1', preg_replace('#//[^\\n\\r]*(\\<\\?php)[^\\n\\r]*(\\s\\?\\>)[^\\n\\r]*#', '', $this->rootDirectory->readFile($file))))))));
if (!$this->htmlDirectory->isExist()) {
$this->htmlDirectory->create();
}
$this->htmlDirectory->writeFile($file, rtrim($content));
}
示例14: getContents
/**
* Returns contents of License file.
*
* @return string|boolean
*/
public function getContents()
{
if ($this->dir->isFile(self::LICENSE_FILENAME)) {
return $this->dir->readFile(self::LICENSE_FILENAME);
} elseif ($this->dir->isFile(self::DEFAULT_LICENSE_FILENAME)) {
return $this->dir->readFile(self::DEFAULT_LICENSE_FILENAME);
} else {
return false;
}
}
示例15: testBasePackageInfo
public function testBasePackageInfo()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
$jsonData = json_encode([BasePackageInfo::COMPOSER_KEY_EXTRA => [BasePackageInfo::COMPOSER_KEY_MAP => [[__FILE__, __FILE__], [__DIR__, __DIR__]]]]);
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
$expectedList = [__FILE__, __DIR__];
$actualList = $this->basePackageInfo->getPaths();
$this->assertEquals($expectedList, $actualList);
}