File tree Expand file tree Collapse file tree 5 files changed +35
-3
lines changed
Bundle/FrameworkBundle/Resources/config Expand file tree Collapse file tree 5 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 21
21
22
22
<service id =" assets.path_package" class =" Symfony\Component\Asset\PathPackage" abstract =" true" >
23
23
<argument /> <!-- base path -->
24
- <argument type = " service " /> <!-- version strategy -->
24
+ <argument /> <!-- version strategy -->
25
25
<argument type =" service" id =" assets.context" />
26
26
</service >
27
27
28
28
<service id =" assets.url_package" class =" Symfony\Component\Asset\UrlPackage" abstract =" true" >
29
29
<argument /> <!-- base URLs -->
30
- <argument type = " service " /> <!-- version strategy -->
30
+ <argument /> <!-- version strategy -->
31
31
<argument type =" service" id =" assets.context" />
32
32
</service >
33
33
Original file line number Diff line number Diff line change @@ -57,7 +57,13 @@ public function getUrl($path)
57
57
return $ path ;
58
58
}
59
59
60
- return $ this ->getBasePath ().ltrim ($ this ->getVersionStrategy ()->applyVersion ($ path ), '/ ' );
60
+ $ versionedPath = $ this ->getVersionStrategy ()->applyVersion ($ path );
61
+
62
+ if ($ this ->isAbsoluteUrl ($ versionedPath )) {
63
+ return $ versionedPath ;
64
+ }
65
+
66
+ return $ this ->getBasePath ().ltrim ($ versionedPath , '/ ' );
61
67
}
62
68
63
69
/**
Original file line number Diff line number Diff line change @@ -75,6 +75,17 @@ public function getContextConfigs()
75
75
);
76
76
}
77
77
78
+ public function testVersionStrategyGivesAbsoluteURL ()
79
+ {
80
+ $ versionStrategy = $ this ->getMockBuilder ('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface ' )->getMock ();
81
+ $ versionStrategy ->expects ($ this ->any ())
82
+ ->method ('applyVersion ' )
83
+ ->willReturn ('https://cdn.com/bar/main.css ' );
84
+ $ package = new PathPackage ('/subdirectory ' , $ versionStrategy , $ this ->getContext ('/bar ' ));
85
+
86
+ $ this ->assertEquals ('https://cdn.com/bar/main.css ' , $ package ->getUrl ('main.css ' ));
87
+ }
88
+
78
89
private function getContext ($ basePath )
79
90
{
80
91
$ context = $ this ->getMockBuilder ('Symfony\Component\Asset\Context\ContextInterface ' )->getMock ();
Original file line number Diff line number Diff line change @@ -77,6 +77,17 @@ public function getContextConfigs()
77
77
);
78
78
}
79
79
80
+ public function testVersionStrategyGivesAbsoluteURL ()
81
+ {
82
+ $ versionStrategy = $ this ->getMockBuilder ('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface ' )->getMock ();
83
+ $ versionStrategy ->expects ($ this ->any ())
84
+ ->method ('applyVersion ' )
85
+ ->willReturn ('https://cdn.com/bar/main.css ' );
86
+ $ package = new UrlPackage ('https://example.com ' , $ versionStrategy );
87
+
88
+ $ this ->assertEquals ('https://cdn.com/bar/main.css ' , $ package ->getUrl ('main.css ' ));
89
+ }
90
+
80
91
/**
81
92
* @expectedException \Symfony\Component\Asset\Exception\LogicException
82
93
*/
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ public function getUrl($path)
81
81
82
82
$ url = $ this ->getVersionStrategy ()->applyVersion ($ path );
83
83
84
+ if ($ this ->isAbsoluteUrl ($ url )) {
85
+ return $ url ;
86
+ }
87
+
84
88
if ($ url && '/ ' != $ url [0 ]) {
85
89
$ url = '/ ' .$ url ;
86
90
}
You can’t perform that action at this time.
0 commit comments