本文整理汇总了PHP中Magento\Framework\View\Asset\Repository::createArbitrary方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::createArbitrary方法的具体用法?PHP Repository::createArbitrary怎么用?PHP Repository::createArbitrary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\Asset\Repository
的用法示例。
在下文中一共展示了Repository::createArbitrary方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Apply customized static files to frontend
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var $themeFile \Magento\Theme\Model\Theme\File */
foreach ($this->currentTheme->getCustomization()->getFiles() as $themeFile) {
try {
$service = $themeFile->getCustomizationService();
if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) {
$identifier = $themeFile->getData('file_path');
$dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME . '/' . $this->currentTheme->getId();
$asset = $this->assetRepo->createArbitrary($identifier, $dirPath, DirectoryList::MEDIA, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$this->pageAssets->add($identifier, $asset);
}
} catch (\InvalidArgumentException $e) {
$this->logger->critical($e);
}
}
}
示例2: testCreateArbitrary
/**
* @return void
*/
public function testCreateArbitrary()
{
$contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\ContextInterface')->disableOriginalConstructor()->getMock();
$this->contextFactoryMock->expects($this->once())->method('create')->with(['baseUrl' => '', 'baseDirType' => 'dirType', 'contextPath' => 'dir/path'])->willReturn($contextMock);
$assetMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->getMock();
$this->fileFactoryMock->expects($this->once())->method('create')->with(['source' => $this->sourceMock, 'context' => $contextMock, 'filePath' => 'test/file.js', 'module' => '', 'contentType' => ''])->willReturn($assetMock);
$this->assertEquals($assetMock, $this->repository->createArbitrary('test/file.js', 'dir/path', 'dirType', 'static'));
}
示例3: testCreateArbitrary
/**
* @param string $filePath
* @param string $dirPath
* @param string $baseUrlType
* @param string $expectedType
* @param string $expectedUrl
* @dataProvider createArbitraryDataProvider
*/
public function testCreateArbitrary($filePath, $dirPath, $baseUrlType, $expectedType, $expectedUrl)
{
$this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValueMap([[['_type' => 'static'], 'http://example.com/static/'], [['_type' => 'media'], 'http://example.com/media/']]));
$dirType = 'dirType';
$asset = $this->object->createArbitrary($filePath, $dirPath, $dirType, $baseUrlType);
$this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset);
$this->assertEquals($expectedType, $asset->getContentType());
$this->assertEquals($expectedUrl, $asset->getUrl());
$this->assertEquals($dirType, $asset->getContext()->getBaseDirType());
$anotherAsset = $this->object->createArbitrary('another/path.js', $dirPath, $dirType, $baseUrlType);
$this->assertSame($anotherAsset->getContext(), $asset->getContext());
}
示例4: createBundleJsPool
/**
* Create a view assets representing the bundle js functionality
*
* @return \Magento\Framework\View\Asset\File[]
*/
public function createBundleJsPool()
{
$bundles = [];
if ($this->appState->getMode() == AppState::MODE_PRODUCTION) {
$libDir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
/** @var $context \Magento\Framework\View\Asset\File\FallbackContext */
$context = $this->assetRepo->getStaticViewFileContext();
$bundleDir = $context->getPath() . '/' . Config::BUNDLE_JS_DIR;
if (!$libDir->isExist($bundleDir)) {
return [];
}
foreach ($libDir->read($bundleDir) as $bundleFile) {
$relPath = $libDir->getRelativePath($bundleFile);
$bundles[] = $this->assetRepo->createArbitrary($relPath, '');
}
}
return $bundles;
}
示例5: createTranslateConfigAsset
/**
* Create a view asset representing the requirejs config.config property for inline translation
*
* @return \Magento\Framework\View\Asset\File
*/
public function createTranslateConfigAsset()
{
return $this->assetRepo->createArbitrary($this->assetRepo->getStaticViewFileContext()->getPath() . '/' . self::TRANSLATION_CONFIG_FILE_NAME, '');
}
示例6: createRequireJsAsset
/**
* Create a view asset representing the aggregated configuration file
*
* @return \Magento\Framework\View\Asset\File
*/
public function createRequireJsAsset()
{
$relPath = $this->config->getConfigFileRelativePath();
$this->ensureSourceFile($relPath);
return $this->assetRepo->createArbitrary($relPath, '');
}