Skip to content

Commit ccc2d00

Browse files
support manifest file (#3)
1 parent e3bc033 commit ccc2d00

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

AssetsBundle/DependencyInjection/Configuration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function addTypes(NodeBuilder $node)
3939
->prototype('array')
4040
->addDefaultsIfNotSet()
4141
->children()
42+
->arrayNode('manifest_assets')
43+
->prototype('scalar')
44+
->end()
45+
->end()
4246
->arrayNode('assets')
4347
->defaultValue([])
4448
->prototype('array')
@@ -95,7 +99,9 @@ private function addOptions(NodeBuilder $nodeBuilder)
9599
->end()
96100
->scalarNode('base_path')
97101
->isRequired()
98-
->end();
102+
->end()
103+
->scalarNode('manifest_file')
104+
->end();
99105
// @formatter:on
100106

101107
return $this;

AssetsBundle/DependencyInjection/DocplannerAssetsExtension.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ public function load(array $configs, ContainerBuilder $container)
5050
$asset['url'] = $url;
5151
$asset['path'] = $path;
5252
}
53+
54+
$manifest = [];
55+
56+
if(!empty($config['manifest_file']))
57+
{
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+
}
66+
67+
foreach($typeConfig['manifest_assets'] ?? [] as $manifestKey)
68+
{
69+
if(!empty($manifest[$manifestKey]))
70+
{
71+
$manifestAsset = $manifest[$manifestKey];
72+
73+
$typeConfig['assets'][$manifestKey] = [
74+
'src' => $manifestAsset,
75+
'url' => $config['base_host'].$manifestAsset,
76+
'path' => $config['base_path'].$manifestAsset,
77+
'inline' => false,
78+
];
79+
}
80+
}
5381
}
5482

5583
$container->setParameter('docplanner_assets.config', $config);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.3.3",
16+
"php": ">=7.1",
1717
"symfony/framework-bundle": "~2.3|~3.0",
1818
"twig/twig": "1.*"
1919
},

0 commit comments

Comments
 (0)