13
13
*/
14
14
class DocplannerAssetsExtension extends Extension
15
15
{
16
+ protected static $ parsedManifests = [];
17
+
16
18
/**
17
19
* {@inheritdoc}
18
20
*/
@@ -53,19 +55,9 @@ public function load(array $configs, ContainerBuilder $container)
53
55
54
56
$ manifest = [];
55
57
56
- if (!empty ($ config ['manifest_file ' ]))
58
+ if (!empty ($ typeConfig ['manifest_file ' ]))
57
59
{
58
- $ manifestFile =$ config ['manifest_file ' ];
59
-
60
- if (is_file ($ manifestFile ) && is_readable ($ manifestFile ))
61
- {
62
- $ manifest = file_get_contents ($ manifestFile );
63
- $ manifest = @json_decode ($ manifest , true ) ?? [];
64
- }
65
- else
66
- {
67
- throw new \RuntimeException (sprintf ('Manifest file `%s` not found ' , $ manifestFile ));
68
- }
60
+ $ manifest = $ this ->loadManifestAssets ($ typeConfig ['manifest_file ' ]);
69
61
}
70
62
71
63
foreach ($ typeConfig ['manifest_assets ' ] ?? [] as $ manifestKey )
@@ -89,4 +81,29 @@ public function load(array $configs, ContainerBuilder $container)
89
81
$ loader = new Loader \YamlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
90
82
$ loader ->load ('services.yml ' );
91
83
}
84
+
85
+ protected function loadManifestAssets ($ manifestFile )
86
+ {
87
+ if (!array_key_exists ($ manifestFile , self ::$ parsedManifests ))
88
+ {
89
+ if (is_file ($ manifestFile ) && is_readable ($ manifestFile ))
90
+ {
91
+ $ manifest = file_get_contents ($ manifestFile );
92
+ $ manifest = @json_decode ($ manifest , true );
93
+
94
+ if (!is_array ($ manifest ))
95
+ {
96
+ throw new \RuntimeException (sprintf ('Cannot parse manifest file `%s` ' , $ manifestFile ));
97
+ }
98
+
99
+ self ::$ parsedManifests [$ manifestFile ] = $ manifest ;
100
+ }
101
+ else
102
+ {
103
+ throw new \RuntimeException (sprintf ('Manifest file `%s` not found ' , $ manifestFile ));
104
+ }
105
+ }
106
+
107
+ return self ::$ parsedManifests [$ manifestFile ];
108
+ }
92
109
}
0 commit comments