File tree 2 files changed +7
-2
lines changed
src/Symfony/Bundle/TwigBundle
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class AssetsExtension extends \Twig_Extension
24
24
private $ container ;
25
25
private $ context ;
26
26
27
- public function __construct (ContainerInterface $ container , RequestContext $ requestContext )
27
+ public function __construct (ContainerInterface $ container , RequestContext $ requestContext = null )
28
28
{
29
29
$ this ->container = $ container ;
30
30
$ this ->context = $ requestContext ;
@@ -94,13 +94,18 @@ public function getName()
94
94
* @param string $url The URL that has to be absolute
95
95
*
96
96
* @return string The absolute URL
97
+ * @throws \RuntimeException
97
98
*/
98
99
private function ensureUrlIsAbsolute ($ url )
99
100
{
100
101
if (false !== strpos ($ url , ':// ' ) || 0 === strpos ($ url , '// ' )) {
101
102
return $ url ;
102
103
}
103
104
105
+ if (!$ this ->context ) {
106
+ throw new \RuntimeException ('To generate an absolute URL for an asset, the Symfony Routing component is required. ' );
107
+ }
108
+
104
109
if ('' === $ host = $ this ->context ->getHost ()) {
105
110
return $ url ;
106
111
}
Original file line number Diff line number Diff line change 66
66
<service id =" twig.extension.assets" class =" %twig.extension.assets.class%" public =" false" >
67
67
<tag name =" twig.extension" />
68
68
<argument type =" service" id =" service_container" />
69
- <argument type =" service" id =" router.request_context" />
69
+ <argument type =" service" id =" router.request_context" on-invalid = " null " />
70
70
</service >
71
71
72
72
<service id =" twig.extension.actions" class =" %twig.extension.actions.class%" public =" false" >
You can’t perform that action at this time.
0 commit comments