123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- /*
- * This file is part of the Sonata project.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\AdminBundle\DependencyInjection;
- use Symfony\Component\Config\Definition\Builder\TreeBuilder;
- use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
- use Symfony\Component\Config\Definition\ConfigurationInterface;
- /**
- * This class contains the configuration information for the bundle
- *
- * This information is solely responsible for how the different configuration
- * sections are normalized, and merged.
- *
- * @author Michael Williams <mtotheikle@gmail.com>
- */
- class Configuration
- {
- /**
- * Generates the configuration tree.
- *
- * @return \Symfony\Component\Config\Definition\NodeInterface
- */
- public function getConfigTree($kernelDebug)
- {
- $treeBuilder = new TreeBuilder();
- $rootNode = $treeBuilder->root('sonata_admin', 'array');
- $this->addTemplateSection($rootNode);
- $this->addAccessControlSection($rootNode);
- $this->addRoleHierarchySection($rootNode);
- return $treeBuilder->buildTree();
- }
- private function addTemplateSection(ArrayNodeDefinition $rootNode)
- {
- $rootNode
- ->children()
- ->arrayNode('templates')
- ->children()
- ->scalarNode('layout')->cannotBeEmpty()->end()
- ->scalarNode('ajax')->cannotBeEmpty()->end()
- ->end()
- ->end()
- ->end()
- ->end();
- }
- private function addAccessControlSection(ArrayNodeDefinition $rootNode)
- {
- $rootNode
- ->fixXmlConfig('rule', 'access_control')
- ->children()
- ->arrayNode('access_control')
- ->cannotBeOverwritten()
- ->prototype('array')
- ->children()
- ->scalarNode('requires_channel')->defaultNull()->end()
- ->scalarNode('path')->defaultNull()->end()
- ->scalarNode('host')->defaultNull()->end()
- ->scalarNode('ip')->defaultNull()->end()
- ->arrayNode('methods')
- ->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->fixXmlConfig('role')
- ->children()
- ->arrayNode('roles')
- ->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ->end()
- ;
- }
- private function addRoleHierarchySection(ArrayNodeDefinition $rootNode)
- {
- $rootNode
- ->fixXmlConfig('role', 'role_hierarchy')
- ->children()
- ->arrayNode('role_hierarchy')
- ->useAttributeAsKey('id')
- ->prototype('array')
- ->performNoDeepMerging()
- ->beforeNormalization()->ifString()->then(function($v) { return array('value' => $v); })->end()
- ->beforeNormalization()
- ->ifTrue(function($v) { return is_array($v) && isset($v['value']); })
- ->then(function($v) { return preg_split('/\s*,\s*/', $v['value']); })
- ->end()
- ->prototype('scalar')->end()
- ->end()
- ->end()
- ->end()
- ;
- }
- }
|