Skip to content

Commit

Permalink
Remove hard dependency of RequestContext in AssetsExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
pgodel committed Aug 26, 2014
1 parent aa58bb8 commit 5ad4d8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
Expand Up @@ -24,7 +24,7 @@ class AssetsExtension extends \Twig_Extension
private $container;
private $context;

public function __construct(ContainerInterface $container, RequestContext $requestContext)
public function __construct(ContainerInterface $container, RequestContext $requestContext = null)
{
$this->container = $container;
$this->context = $requestContext;
Expand Down Expand Up @@ -94,13 +94,18 @@ public function getName()
* @param string $url The URL that has to be absolute
*
* @return string The absolute URL
* @throws \RuntimeException
*/
private function ensureUrlIsAbsolute($url)
{
if (false !== strpos($url, '://') || 0 === strpos($url, '//')) {
return $url;
}

if (!$this->context) {
throw new \RuntimeException('To generate an absolute URL for an asset, the Symfony Routing component is required.');
}

if ('' === $host = $this->context->getHost()) {
return $url;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -66,7 +66,7 @@
<service id="twig.extension.assets" class="%twig.extension.assets.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="service_container" />
<argument type="service" id="router.request_context" />
<argument type="service" id="router.request_context" on-invalid="null" />
</service>

<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
Expand Down

0 comments on commit 5ad4d8a

Please sign in to comment.