/** * Returns the public path of an asset in the pattens. * * Absolute paths (i.e. http://...) are returned unmodified. * * @param string $type A type assets * @param string $packageName The name of the asset package to use * @param bool $absolute Whether to return an absolute URL or a relative one * @param string|bool|null $version A specific version * * @return string */ public function assetsFunction($type = 'stylesheets', $packageName = null, $absolute = false, $version = null) { $string = ''; $data = isset($this->assets[$type]) ? $this->assets[$type] : array(); if (isset($this->pattern[$type])) { foreach ($data as $value) { $url = $this->extension->getAssetUrl($value, $packageName, $absolute, $version); $string .= str_replace('{{ value }}', $url, $this->pattern[$type]); } } return $string; }
function it_compute_file_asset_path(File $file, AssetsExtension $assets, FSiFilePathResolver $filePathResolver) { $file->getKey()->willReturn('file-name.txt'); $filePathResolver->filePath($file, 'uploaded')->willReturn('/uploaded/file-name.txt'); $assets->getAssetUrl('/uploaded/file-name.txt')->willReturn('/uploaded/file-name.txt'); $this->fileAsset($file, 'uploaded')->shouldReturn('/uploaded/file-name.txt'); }
public function testGetAssetWithoutHost() { $path = '/path/to/asset'; $packageName = null; $relativeUrl = '/bundle-name/path/to/asset'; $helper = $this->createHelperMock($path, $packageName, $relativeUrl); $container = $this->createContainerMock($helper); $context = $this->createRequestContextMock('http', '', 80, 443); $extension = new AssetsExtension($container, $context); $this->assertEquals($relativeUrl, $extension->getAssetUrl($path, $packageName, true)); }
public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null) { if ($path[0] == '@') { // exptected $segments = explode('/', $path); $bundle = ltrim(array_shift($segments), '@'); $assetPath = implode('/', $segments); $bundle = $this->container->get('kernel')->getBundle($bundle); $bundleAssetPath = $this->getBundleAssetPath($bundle); $path = $bundleAssetPath . '/' . $assetPath; } return parent::getAssetUrl($path, $packageName, $absolute, $version); }
public function fileAsset(File $file, $prefix = null) { return $this->assets->getAssetUrl($this->filePathResolver->filePath($file, $prefix)); }