1313
1414use OleksiiBulba \WebpackEncorePlugin \Asset \EntrypointLookupInterface ;
1515
16- class TagRenderer implements TagRendererInterface
16+ readonly class TagRenderer implements TagRendererInterface
1717{
1818 public function __construct (
19- private readonly EntrypointLookupInterface $ entrypointLookup ,
20- private readonly array $ defaultAttributes = [],
21- private readonly array $ defaultScriptAttributes = ['type ' => 'application/javascript ' ],
22- private readonly array $ defaultLinkAttributes = []
19+ private EntrypointLookupInterface $ entrypointLookup ,
20+ private array $ defaultAttributes = [],
21+ private array $ defaultScriptAttributes = ['type ' => 'application/javascript ' ],
22+ private array $ defaultLinkAttributes = [' rel ' => ' stylesheet ' ]
2323 ) {
2424 }
2525
@@ -28,13 +28,14 @@ public function renderWebpackScriptTags(string $entryName, array $extraAttribute
2828 $ scriptTags = [];
2929
3030 foreach ($ this ->entrypointLookup ->getJavaScriptFiles ($ entryName ) as $ filename ) {
31- $ attributes = [];
32- $ attributes ['src ' ] = $ filename ;
33- $ attributes = array_merge ($ attributes , $ this ->defaultAttributes , $ this ->defaultScriptAttributes , $ extraAttributes );
34-
3531 $ scriptTags [] = sprintf (
3632 /* @lang text */ '<script %s></script> ' ,
37- $ this ->convertArrayToAttributes ($ attributes )
33+ $ this ->convertArrayToAttributes (array_merge (
34+ ['src ' => $ filename ],
35+ $ this ->defaultAttributes ,
36+ $ this ->defaultScriptAttributes ,
37+ $ extraAttributes
38+ ))
3839 );
3940 }
4041
@@ -46,14 +47,14 @@ public function renderWebpackLinkTags(string $entryName, array $extraAttributes
4647 $ scriptTags = [];
4748
4849 foreach ($ this ->entrypointLookup ->getCssFiles ($ entryName ) as $ filename ) {
49- $ attributes = [];
50- $ attributes ['rel ' ] = 'stylesheet ' ;
51- $ attributes ['href ' ] = $ filename ;
52- $ attributes = array_merge ($ attributes , $ this ->defaultAttributes , $ this ->defaultLinkAttributes , $ extraAttributes );
53-
5450 $ scriptTags [] = sprintf (
5551 /* @lang text */ '<link %s> ' ,
56- $ this ->convertArrayToAttributes ($ attributes )
52+ $ this ->convertArrayToAttributes (array_merge (
53+ ['href ' => $ filename ],
54+ $ this ->defaultAttributes ,
55+ $ this ->defaultLinkAttributes ,
56+ $ extraAttributes
57+ ))
5758 );
5859 }
5960
@@ -68,9 +69,9 @@ private function convertArrayToAttributes(array $attributesMap): string
6869 });
6970
7071 return implode (' ' , array_map (
71- static function ($ key , string |null | bool $ value ) {
72+ static function ($ key , string |true | null $ value ) {
7273 // allows for things like defer: true to only render "defer"
73- if (\is_bool ( $ value) || null === $ value ) {
74+ if (true === $ value || null === $ value ) {
7475 return $ key ;
7576 }
7677
0 commit comments