. */ namespace Sikofitt\App\Configuration; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class DatabaseConfiguration implements ConfigurationInterface { public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('doughnut'); $rootNode->children() ->arrayNode('connections') ->prototype('array') ->children() ->arrayNode('connection') ->children() ->scalarNode('driver') ->isRequired() ->validate() ->ifNotInArray(['pdo_mysql', 'pdo_pgsql', 'pdo_sqlite']) ->thenInvalid('Invalid driver : %s') ->end() // ifNotInArray ->end() // driver ->scalarNode('dbname')->isRequired()->end() // database ->scalarNode('host')->defaultValue('127.0.0.1')->end() ->scalarNode('user')->isRequired()->end() ->scalarNode('password')->isRequired()->end() ->end() // connection.prototype ->end() // connection ->arrayNode('annotation_autoloaders') ->requiresAtLeastOneElement() ->prototype('scalar') ->isRequired() ->end() ->end() ->arrayNode('metadata_mapping') ->prototype('array') ->children() ->arrayNode('path') ->requiresAtLeastOneElement() ->prototype('scalar') ->isRequired() ->end() ->end() ->scalarNode('type') ->isRequired() ->beforeNormalization() ->ifString() ->then(function ($s) { return $this->normalizeConstant($s); }) ->end() ->end() ->end() ->end() ->end() ->end(); return $treeBuilder; } private function normalizeConstant($const) { $classParts = explode('::', $const); if (isset($classParts[1])) { $reflected = new \ReflectionClass($classParts[0]); $constant = $reflected->getConstant($classParts[1]); return $constant; } else { return $const; } } }