本文整理匯總了PHP中Magento\Framework\View\FileSystem類的典型用法代碼示例。如果您正苦於以下問題:PHP FileSystem類的具體用法?PHP FileSystem怎麽用?PHP FileSystem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FileSystem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetTemplateFileName
/**
* Resolver get template file name test
*
* @return void
*/
public function testGetTemplateFileName()
{
$template = 'template.phtml';
$this->_viewFileSystemMock->expects($this->once())->method('getTemplateFileName')->with($template)->will($this->returnValue('path_to' . $template));
$this->assertEquals('path_to' . $template, $this->_resolver->getTemplateFileName($template));
$this->assertEquals('path_to' . $template, $this->_resolver->getTemplateFileName($template));
}
示例2: getTemplateFileName
/**
* Get template filename
*
* @param string $template
* @param [] $params
* @return string|bool
*/
public function getTemplateFileName($template, $params = [])
{
$key = $template . '_' . serialize($params);
if (!isset($this->_templateFilesMap[$key])) {
$this->_templateFilesMap[$key] = $this->_viewFileSystem->getTemplateFileName($template, $params);
}
return $this->_templateFilesMap[$key];
}
示例3: testReferencesFromStaticFiles
/**
* Scan references to files from other static files and assert they are correct
*
* The CSS or LESS files may refer to other resources using @import or url() notation
* We want to check integrity of all these references
* Note that the references may have syntax specific to the Magento preprocessing subsystem
*
* @param string $area
* @param string $themePath
* @param string $locale
* @param string $module
* @param string $filePath
* @param string $absolutePath
* @dataProvider referencesFromStaticFilesDataProvider
*/
public function testReferencesFromStaticFiles($area, $themePath, $locale, $module, $filePath, $absolutePath)
{
$contents = file_get_contents($absolutePath);
preg_match_all(\Magento\Framework\View\Url\CssResolver::REGEX_CSS_RELATIVE_URLS, $contents, $matches);
foreach ($matches[1] as $relatedResource) {
if (false !== strpos($relatedResource, '@')) {
// unable to parse paths with LESS variables/mixins
continue;
}
list($relatedModule, $relatedPath) = \Magento\Framework\View\Asset\Repository::extractModule($relatedResource);
if ($relatedModule) {
$fallbackModule = $relatedModule;
} else {
if ('less' == pathinfo($filePath, PATHINFO_EXTENSION)) {
/**
* The LESS library treats the related resources with relative links not in the same way as CSS:
* when another LESS file is included, it is embedded directly into the resulting document, but the
* relative paths of related resources are not adjusted accordingly to the new root file.
* Probably it is a bug of the LESS library.
*/
$this->markTestSkipped("Due to LESS library specifics, the '{$relatedResource}' cannot be tested.");
}
$fallbackModule = $module;
$relatedPath = \Magento\Framework\View\FileSystem::getRelatedPath($filePath, $relatedResource);
}
// the $relatedPath will be suitable for feeding to the fallback system
$this->assertNotEmpty($this->getStaticFile($area, $themePath, $locale, $relatedPath, $fallbackModule), "The related resource cannot be resolved through fallback: '{$relatedResource}'");
}
}
示例4: 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());
}
示例5: _getThemeTranslationFile
/**
* Retrieve translation file for theme
*
* @param string $locale
* @return string
*/
protected function _getThemeTranslationFile($locale)
{
return $this->_viewFileSystem->getLocaleFileName(
'i18n' . '/' . $locale . '.csv',
['area' => $this->getConfig('area')]
);
}
示例6: getViewConfig
/**
* Render view config object for current package and theme
*
* @param array $params
* @return \Magento\Framework\Config\View
*/
public function getViewConfig(array $params = [])
{
$this->assetRepo->updateDesignParams($params);
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
$currentTheme = $params['themeModel'];
$key = $currentTheme->getCode();
if (isset($this->viewConfigs[$key])) {
return $this->viewConfigs[$key];
}
$configFiles = $this->moduleReader->getConfigurationFiles(basename($this->filename))->toArray();
$themeConfigFile = $currentTheme->getCustomization()->getCustomViewConfigPath();
if (empty($themeConfigFile)
|| !$this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$themeConfigFile = $this->viewFileSystem->getFilename($this->filename, $params);
}
if ($themeConfigFile
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$configFiles[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile(
$this->rootDirectory->getRelativePath($themeConfigFile)
);
}
$config = $this->viewFactory->create($configFiles);
$this->viewConfigs[$key] = $config;
return $config;
}
示例7: generateLayoutUpdateXml
/**
* Generate layout update xml
*
* @param string $container
* @param string $templatePath
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function generateLayoutUpdateXml($container, $templatePath = '')
{
$templateFilename = $this->_viewFileSystem->getTemplateFileName($templatePath, ['area' => $this->getArea(), 'themeId' => $this->getThemeId(), 'module' => \Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->getType())]);
if (!$this->getId() && !$this->isCompleteToCreate() || $templatePath && !is_readable($templateFilename)) {
return '';
}
$parameters = $this->getWidgetParameters();
$xml = '<body><referenceContainer name="' . $container . '">';
$template = '';
if (isset($parameters['template'])) {
unset($parameters['template']);
}
if ($templatePath) {
$template = ' template="' . $templatePath . '"';
}
$hash = $this->mathRandom->getUniqueHash();
$xml .= '<block class="' . $this->getType() . '" name="' . $hash . '"' . $template . '>';
foreach ($parameters as $name => $value) {
if ($name == 'conditions') {
$name = 'conditions_encoded';
$value = $this->conditionsHelper->encode($value);
} elseif (is_array($value)) {
$value = implode(',', $value);
}
if ($name && strlen((string) $value)) {
$xml .= '<action method="setData">' . '<argument name="name" xsi:type="string">' . $name . '</argument>' . '<argument name="value" xsi:type="string">' . $this->_escaper->escapeHtml($value) . '</argument>' . '</action>';
}
}
$xml .= '</block></referenceContainer></body>';
return $xml;
}
示例8: relocateRelativeUrls
/**
* Adjust relative URLs in CSS content as if the file with this content is to be moved to new location
*
* @param string $cssContent
* @param string $relatedPath
* @param string $filePath
* @return mixed
*/
public function relocateRelativeUrls($cssContent, $relatedPath, $filePath)
{
$offset = FileSystem::offsetPath($relatedPath, $filePath);
$callback = function ($path) use($offset) {
return FileSystem::normalizePath($offset . '/' . $path);
};
return $this->replaceRelativeUrls($cssContent, $callback);
}
示例9: testGetWidgetSupportedTemplatesByContainersUnknownContainer
public function testGetWidgetSupportedTemplatesByContainersUnknownContainer()
{
$expectedConfigFile = __DIR__ . '/../_files/mappedConfigArray1.php';
$widget = (include $expectedConfigFile);
$this->_widgetModelMock->expects($this->once())->method('getWidgetByClassType')->will($this->returnValue($widget));
$this->_viewFileSystemMock->expects($this->once())->method('getFilename')->will($this->returnValue(''));
$expectedTemplates = [];
$this->assertEquals($expectedTemplates, $this->_model->getWidgetSupportedTemplatesByContainer('unknown'));
}
示例10: testToHtmlWithoutRatingData
public function testToHtmlWithoutRatingData()
{
$this->registry->expects($this->any())->method('registry')->will($this->returnValue(false));
$this->systemStore->expects($this->any())->method('getStoreCollection')->will($this->returnValue(['0' => $this->store]));
$this->formFactory->expects($this->any())->method('create')->will($this->returnValue($this->form));
$this->viewFileSystem->expects($this->any())->method('getTemplateFileName')->will($this->returnValue('template_file_name.html'));
$this->fileSystem->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->directoryReadInterface));
$this->block->toHtml();
}
示例11: getTemplateFile
/**
* Get absolute path to template
*
* @param string|null $template
* @return string
*/
public function getTemplateFile($template = null)
{
$params = ['module' => $this->getModuleName()];
$area = $this->getArea();
if ($area) {
$params['area'] = $area;
}
$templateName = $this->_viewFileSystem->getTemplateFileName($template ?: $this->getTemplate(), $params);
return $templateName;
}
示例12: getTemplateFilename
/**
* Retrieve full path to an email template file
*
* @param string $templateId
* @param array|null $designParams
* @return string
*/
public function getTemplateFilename($templateId, $designParams = [])
{
// If design params aren't passed, then use area/module defined in email_templates.xml
if (!isset($designParams['area'])) {
$designParams['area'] = $this->getTemplateArea($templateId);
}
$module = $this->getTemplateModule($templateId);
$designParams['module'] = $module;
$file = $this->_getInfo($templateId, 'file');
return $this->viewFileSystem->getEmailTemplateFileName($file, $designParams, $module);
}
示例13: setUp
protected function setUp()
{
$this->_viewFileSystem = $this->getMock('Magento\\Framework\\View\\FileSystem', array('getLocaleFileName', 'getDesignTheme'), array(), '', false);
$this->_viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue(dirname(__DIR__) . '/Core/Model/_files/design/frontend/test_default/i18n/en_US.csv'));
$theme = $this->getMock('\\Magento\\Framework\\View\\Design\\ThemeInterface', array());
$theme->expects($this->any())->method('getId')->will($this->returnValue(10));
$this->_viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->addSharedInstance($this->_viewFileSystem, 'Magento\\Framework\\View\\FileSystem');
/** @var $moduleReader \Magento\Framework\Module\Dir\Reader */
$moduleReader = $objectManager->get('Magento\\Framework\\Module\\Dir\\Reader');
$moduleReader->setModuleDir('Magento_Core', 'i18n', dirname(__DIR__) . '/Core/Model/_files/Magento/Core/i18n');
$moduleReader->setModuleDir('Magento_Catalog', 'i18n', dirname(__DIR__) . '/Core/Model/_files/Magento/Catalog/i18n');
/** @var \Magento\Core\Model\View\Design _designModel */
$this->_designModel = $this->getMock('Magento\\Core\\Model\\View\\Design', array('getDesignTheme'), array($objectManager->get('Magento\\Framework\\StoreManagerInterface'), $objectManager->get('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory'), $objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface'), $objectManager->get('Magento\\Core\\Model\\ThemeFactory'), $objectManager->get('Magento\\Framework\\Locale\\ResolverInterface'), $objectManager->get('Magento\\Framework\\App\\State'), array('frontend' => 'test_default')));
$this->_designModel->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
$objectManager->addSharedInstance($this->_designModel, 'Magento\\Core\\Model\\View\\Design\\Proxy');
$this->_model = $objectManager->create('Magento\\Framework\\Translate');
$objectManager->addSharedInstance($this->_model, 'Magento\\Framework\\Translate');
$objectManager->removeSharedInstance('Magento\\Framework\\Phrase\\Renderer\\Composite');
$objectManager->removeSharedInstance('Magento\\Framework\\Phrase\\Renderer\\Translate');
\Magento\Framework\Phrase::setRenderer($objectManager->get('Magento\\Framework\\Phrase\\RendererInterface'));
$this->_model->loadData(\Magento\Framework\App\Area::AREA_FRONTEND);
}
示例14: renderPage
/**
* Render page template
*
* @return string
* @throws \Exception
*/
protected function renderPage()
{
$fileName = $this->viewFileSystem->getTemplateFileName($this->template);
if (!$fileName) {
throw new \InvalidArgumentException('Template "' . $this->template . '" is not found');
}
ob_start();
try {
extract($this->viewVars, EXTR_SKIP);
include $fileName;
} catch (\Exception $exception) {
ob_end_clean();
throw $exception;
}
$output = ob_get_clean();
return $output;
}
示例15: testGetTemplateFilenameWithNoParams
/**
* Ensure that the getTemplateFilename method can be called without design params
*/
public function testGetTemplateFilenameWithNoParams()
{
$this->viewFileSystem->expects($this->once())->method('getEmailTemplateFileName')->with('one.html', ['area' => $this->designParams['area'], 'module' => $this->designParams['module']], 'Fixture_ModuleOne')->will($this->returnValue('_files/Fixture/ModuleOne/view/frontend/email/one.html'));
$actualResult = $this->model->getTemplateFilename('template_one');
$this->assertEquals('_files/Fixture/ModuleOne/view/frontend/email/one.html', $actualResult);
}