diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php index 57c2fb9bf8..a1074a9479 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php @@ -151,6 +151,10 @@ class WebExtension extends Extension $container->setParameter('templating.assets.version', $config['assets_version']); } + if (array_key_exists('assets_base_urls', $config)) { + $container->setParameter('templating.assets.base_urls', $config['assets_base_urls']); + } + // template paths $dirs = array('%kernel.root_dir%/views/%%bundle%%/%%controller%%/%%name%%%%format%%.%%renderer%%'); foreach ($container->getParameter('kernel.bundle_dirs') as $dir) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 6855b7d962..5899c22ff2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -20,6 +20,7 @@ Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper false null + null @@ -64,7 +65,7 @@ - + %templating.assets.base_urls% %templating.assets.version% diff --git a/src/Symfony/Components/Templating/Helper/AssetsHelper.php b/src/Symfony/Components/Templating/Helper/AssetsHelper.php index e2c84b1c43..7f229cac15 100644 --- a/src/Symfony/Components/Templating/Helper/AssetsHelper.php +++ b/src/Symfony/Components/Templating/Helper/AssetsHelper.php @@ -148,15 +148,16 @@ class AssetsHelper extends Helper */ public function getUrl($path) { - if (strpos($path, '://')) { + if (false !== strpos($path, '://')) { return $path; } + $base = $this->getBaseURL($path); if (0 !== strpos($path, '/')) { - $path = $this->basePath.$path; + $path = $base ? '/'.$path : $this->basePath.$path; } - return $this->getBaseURL($path).$path.($this->version ? '?'.$this->version : ''); + return $base.$path.($this->version ? '?'.$this->version : ''); } /** diff --git a/tests/Symfony/Tests/Components/Templating/Helper/AssetsTest.php b/tests/Symfony/Tests/Components/Templating/Helper/AssetsTest.php index 1423ab2b71..58f5bf559f 100644 --- a/tests/Symfony/Tests/Components/Templating/Helper/AssetsTest.php +++ b/tests/Symfony/Tests/Components/Templating/Helper/AssetsTest.php @@ -82,14 +82,14 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL with a path'); $helper = new AssetsHelper('/foo', 'http://www.example.com/'); - $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined'); + $this->assertEquals('http://www.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined'); $this->assertEquals('http://www.example.com/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL but not the base path on absolute paths'); $helper = new AssetsHelper('/bar', 'http://www.example.com/foo'); - $this->assertEquals('http://www.example.com/foo/bar/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined'); + $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined'); $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL but not the base path on absolute paths'); $helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd'); - $this->assertEquals('http://www.example.com/foo/bar/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined'); + $this->assertEquals('http://www.example.com/foo/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined'); } }