75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace FOQ\ElasticaBundle\DependencyInjection;
|
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
|
|
|
class Configuration
|
|
{
|
|
/**
|
|
* Generates the configuration tree.
|
|
*
|
|
* @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface
|
|
*/
|
|
public function getConfigTree()
|
|
{
|
|
$treeBuilder = new TreeBuilder();
|
|
$rootNode = $treeBuilder->root('foq_elastica', 'array');
|
|
|
|
$this->addClientsSection($rootNode);
|
|
$this->addIndexesSection($rootNode);
|
|
|
|
$rootNode
|
|
->children()
|
|
->scalarNode('default_client')->end()
|
|
->end()
|
|
;
|
|
|
|
return $treeBuilder->buildTree();
|
|
}
|
|
|
|
/**
|
|
* Adds the configuration for the "clients" key
|
|
*/
|
|
private function addClientsSection(ArrayNodeDefinition $rootNode)
|
|
{
|
|
$rootNode
|
|
->fixXmlConfig('client')
|
|
->children()
|
|
->arrayNode('clients')
|
|
->useAttributeAsKey('id')
|
|
->prototype('array')
|
|
->performNoDeepMerging()
|
|
->children()
|
|
->scalarNode('host')->defaultValue('localhost')->end()
|
|
->scalarNode('port')->defaultValue('9000')->end()
|
|
->end()
|
|
->end()
|
|
->end()
|
|
->end()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* Adds the configuration for the "indexes" key
|
|
*/
|
|
private function addIndexesSection(ArrayNodeDefinition $rootNode)
|
|
{
|
|
$rootNode
|
|
->fixXmlConfig('index')
|
|
->children()
|
|
->arrayNode('indexes')
|
|
->useAttributeAsKey('id')
|
|
->prototype('array')
|
|
->performNoDeepMerging()
|
|
->children()
|
|
->scalarNode('client')->end()
|
|
->end()
|
|
->end()
|
|
->end()
|
|
->end()
|
|
;
|
|
}
|
|
}
|