1010namespace Symfony \WebpackEncoreBundle \Asset ;
1111
1212use Symfony \Component \Asset \Packages ;
13+ use Symfony \Component \DependencyInjection \ServiceLocator ;
1314
1415final class TagRenderer
1516{
16- private $ entrypointLookup ;
17+ private $ entrypointLookupCollection ;
1718
1819 private $ packages ;
1920
20- public function __construct (EntrypointLookupInterface $ entrypointLookup , Packages $ packages )
21- {
22- $ this ->entrypointLookup = $ entrypointLookup ;
21+ public function __construct (
22+ $ entrypointLookupCollection ,
23+ Packages $ packages
24+ ) {
25+ if ($ entrypointLookupCollection instanceof EntrypointLookupInterface) {
26+ @trigger_error (sprintf ('The "$entrypointLookupCollection" argument in method "%s()" must be an instance of EntrypointLookupCollection. ' , __METHOD__ ), E_USER_DEPRECATED );
27+
28+ $ this ->entrypointLookupCollection = new EntrypointLookupCollection (
29+ new ServiceLocator (['_default ' => function () use ($ entrypointLookupCollection ) {
30+ return $ entrypointLookupCollection ;
31+ }])
32+ );
33+ } elseif ($ entrypointLookupCollection instanceof EntrypointLookupCollection) {
34+ $ this ->entrypointLookupCollection = $ entrypointLookupCollection ;
35+ } else {
36+ throw new \TypeError ('The "$entrypointLookupCollection" argument must be an instance of EntrypointLookupCollection. ' );
37+ }
38+
2339 $ this ->packages = $ packages ;
2440 }
2541
26- public function renderWebpackScriptTags (string $ entryName , string $ packageName = null ): string
42+ public function renderWebpackScriptTags (string $ entryName , string $ packageName = null , string $ entrypointName = ' _default ' ): string
2743 {
2844 $ scriptTags = [];
29- foreach ($ this ->entrypointLookup ->getJavaScriptFiles ($ entryName ) as $ filename ) {
45+ foreach ($ this ->getEntrypointLookup ( $ entrypointName ) ->getJavaScriptFiles ($ entryName ) as $ filename ) {
3046 $ scriptTags [] = sprintf (
3147 '<script src="%s"></script> ' ,
3248 htmlentities ($ this ->getAssetPath ($ filename , $ packageName ))
@@ -36,10 +52,10 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
3652 return implode ('' , $ scriptTags );
3753 }
3854
39- public function renderWebpackLinkTags (string $ entryName , string $ packageName = null ): string
55+ public function renderWebpackLinkTags (string $ entryName , string $ packageName = null , string $ entrypointName = ' _default ' ): string
4056 {
4157 $ scriptTags = [];
42- foreach ($ this ->entrypointLookup ->getCssFiles ($ entryName ) as $ filename ) {
58+ foreach ($ this ->getEntrypointLookup ( $ entrypointName ) ->getCssFiles ($ entryName ) as $ filename ) {
4359 $ scriptTags [] = sprintf (
4460 '<link rel="stylesheet" href="%s"> ' ,
4561 htmlentities ($ this ->getAssetPath ($ filename , $ packageName ))
@@ -60,4 +76,9 @@ private function getAssetPath(string $assetPath, string $packageName = null): st
6076 $ packageName
6177 );
6278 }
79+
80+ private function getEntrypointLookup (string $ buildName ): EntrypointLookupInterface
81+ {
82+ return $ this ->entrypointLookupCollection ->getEntrypointLookup ($ buildName );
83+ }
6384}
0 commit comments