10
10
namespace Symfony \WebpackEncoreBundle \Asset ;
11
11
12
12
use Symfony \Component \Asset \Packages ;
13
+ use Symfony \Component \DependencyInjection \ServiceLocator ;
13
14
14
15
final class TagRenderer
15
16
{
16
- private $ entrypointLookup ;
17
+ private $ entrypointLookupCollection ;
17
18
18
19
private $ packages ;
19
20
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
+
23
39
$ this ->packages = $ packages ;
24
40
}
25
41
26
- public function renderWebpackScriptTags (string $ entryName , string $ packageName = null ): string
42
+ public function renderWebpackScriptTags (string $ entryName , string $ packageName = null , string $ entrypointName = ' _default ' ): string
27
43
{
28
44
$ scriptTags = [];
29
- foreach ($ this ->entrypointLookup ->getJavaScriptFiles ($ entryName ) as $ filename ) {
45
+ foreach ($ this ->getEntrypointLookup ( $ entrypointName ) ->getJavaScriptFiles ($ entryName ) as $ filename ) {
30
46
$ scriptTags [] = sprintf (
31
47
'<script src="%s"></script> ' ,
32
48
htmlentities ($ this ->getAssetPath ($ filename , $ packageName ))
@@ -36,10 +52,10 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
36
52
return implode ('' , $ scriptTags );
37
53
}
38
54
39
- public function renderWebpackLinkTags (string $ entryName , string $ packageName = null ): string
55
+ public function renderWebpackLinkTags (string $ entryName , string $ packageName = null , string $ entrypointName = ' _default ' ): string
40
56
{
41
57
$ scriptTags = [];
42
- foreach ($ this ->entrypointLookup ->getCssFiles ($ entryName ) as $ filename ) {
58
+ foreach ($ this ->getEntrypointLookup ( $ entrypointName ) ->getCssFiles ($ entryName ) as $ filename ) {
43
59
$ scriptTags [] = sprintf (
44
60
'<link rel="stylesheet" href="%s"> ' ,
45
61
htmlentities ($ this ->getAssetPath ($ filename , $ packageName ))
@@ -60,4 +76,9 @@ private function getAssetPath(string $assetPath, string $packageName = null): st
60
76
$ packageName
61
77
);
62
78
}
79
+
80
+ private function getEntrypointLookup (string $ buildName ): EntrypointLookupInterface
81
+ {
82
+ return $ this ->entrypointLookupCollection ->getEntrypointLookup ($ buildName );
83
+ }
63
84
}
0 commit comments