Skip to content

Commit c130221

Browse files
multi manifest files
1 parent de1fead commit c130221

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

AssetsBundle/DependencyInjection/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function addTypes(NodeBuilder $node)
3939
->prototype('array')
4040
->addDefaultsIfNotSet()
4141
->children()
42+
->scalarNode('manifest_file')
43+
->end()
4244
->arrayNode('manifest_assets')
4345
->prototype('scalar')
4446
->end()
@@ -99,9 +101,7 @@ private function addOptions(NodeBuilder $nodeBuilder)
99101
->end()
100102
->scalarNode('base_path')
101103
->isRequired()
102-
->end()
103-
->scalarNode('manifest_file')
104-
->end();
104+
->end();
105105
// @formatter:on
106106

107107
return $this;

AssetsBundle/DependencyInjection/DocplannerAssetsExtension.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class DocplannerAssetsExtension extends Extension
1515
{
16+
protected static $parsedManifests = [];
17+
1618
/**
1719
* {@inheritdoc}
1820
*/
@@ -53,19 +55,9 @@ public function load(array $configs, ContainerBuilder $container)
5355

5456
$manifest = [];
5557

56-
if(!empty($config['manifest_file']))
58+
if(!empty($typeConfig['manifest_file']))
5759
{
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']);
6961
}
7062

7163
foreach($typeConfig['manifest_assets'] ?? [] as $manifestKey)
@@ -89,4 +81,29 @@ public function load(array $configs, ContainerBuilder $container)
8981
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
9082
$loader->load('services.yml');
9183
}
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+
}
92109
}

0 commit comments

Comments
 (0)