Skip to content

Commit f62f007

Browse files
committed
configuration
1 parent 3ba9e51 commit f62f007

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

AssetsBundle/DependencyInjection/Configuration.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Docplanner\AssetsBundle\DependencyInjection;
44

5-
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
5+
use Symfony\Component\Config\Definition\Builder\NodeBuilder;use Symfony\Component\Config\Definition\Builder\TreeBuilder;
66
use Symfony\Component\Config\Definition\ConfigurationInterface;
77

88
/**
99
* This is the class that validates and merges configuration from your app/config files
10-
*
1110
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
1211
*/
1312
class Configuration implements ConfigurationInterface
@@ -20,10 +19,65 @@ public function getConfigTreeBuilder()
2019
$treeBuilder = new TreeBuilder();
2120
$rootNode = $treeBuilder->root('docplanner_assets');
2221

22+
$nodeBuilder = $rootNode->children();
23+
$this->addNode($nodeBuilder, 'style');
24+
$this->addNode($nodeBuilder, 'script');
25+
2326
// Here you should define the parameters that are allowed to
2427
// configure your bundle. See the documentation linked above for
2528
// more information on that topic.
2629

2730
return $treeBuilder;
2831
}
32+
33+
/**
34+
* @param NodeBuilder $node
35+
* @param string $name
36+
*
37+
* @return NodeBuilder
38+
*/
39+
public function addNode(NodeBuilder $node, $name)
40+
{
41+
// @formatter:off
42+
/** @noinspection PhpUndefinedMethodInspection */
43+
$node->arrayNode($name)
44+
->addDefaultsIfNotSet()
45+
->children()
46+
->arrayNode('assets')
47+
->defaultValue([])
48+
->prototype('array')
49+
->children()
50+
->scalarNode('src')
51+
->isRequired()
52+
->end()
53+
->scalarNode('inline')
54+
->defaultFalse()
55+
->end()
56+
->end()
57+
->end()
58+
->end()
59+
->arrayNode('groups')
60+
->defaultValue([])
61+
->prototype('array')
62+
->children()
63+
->booleanNode('default')
64+
->defaultFalse()
65+
->end()
66+
->arrayNode('assets')
67+
->prototype('scalar')
68+
->end()
69+
->end()
70+
->arrayNode('routes')
71+
->defaultValue([])
72+
->prototype('scalar')
73+
->end()
74+
->end()
75+
->end()
76+
->end()
77+
->end()
78+
->end();
79+
// @formatter:on
80+
81+
return $node;
82+
}
2983
}

AssetsBundle/DependencyInjection/DocplannerAssetsExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function load(array $configs, ContainerBuilder $container)
2222
$configuration = new Configuration();
2323
$config = $this->processConfiguration($configuration, $configs);
2424

25+
$container->setParameter('docplanner_assets.configuration', $config);
26+
2527
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2628
$loader->load('services.yml');
2729
}

0 commit comments

Comments
 (0)