Started to integrate the new configuration system (still WIP/dirty)
This commit is contained in:
parent
48b29243f3
commit
09e4da0c19
13 changed files with 53 additions and 413 deletions
|
|
@ -10,237 +10,11 @@
|
|||
|
||||
namespace Propel\PropelBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Propel\Common\Config\PropelConfiguration;
|
||||
|
||||
/**
|
||||
* 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 William DURAND <william.durand1@gmail.com>
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
class Configuration extends PropelConfiguration
|
||||
{
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Boolean $debug Wether to use the debug mode
|
||||
*/
|
||||
public function __construct($debug)
|
||||
{
|
||||
$this->debug = (Boolean) $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the configuration tree builder.
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('propel');
|
||||
|
||||
$this->addGeneralSection($rootNode);
|
||||
$this->addDbalSection($rootNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds 'general' configuration.
|
||||
*
|
||||
* propel:
|
||||
* logging: %kernel.debug%
|
||||
* build_properties:
|
||||
* xxxx.xxxx: xxxxxx
|
||||
* ...
|
||||
* behaviors:
|
||||
* fooable: My\FooableBehavior
|
||||
* barable: src.barable.BarableBehavior
|
||||
*/
|
||||
private function addGeneralSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->scalarNode('logging')->defaultValue($this->debug)->end()
|
||||
->arrayNode('build_properties')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->arrayNode('behaviors')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds 'dbal' configuration.
|
||||
*
|
||||
* propel:
|
||||
* dbal:
|
||||
* driver: mysql
|
||||
* user: root
|
||||
* password: null
|
||||
* dsn: xxxxxxxx
|
||||
* options: {}
|
||||
* attributes: {}
|
||||
* settings: {}
|
||||
* default_connection: xxxxxx
|
||||
*/
|
||||
private function addDbalSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('dbal')
|
||||
->beforeNormalization()
|
||||
->ifNull()
|
||||
->then(function ($v) { return array ('connections' => array('default' => array())); })
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('default_connection')->defaultValue('default')->end()
|
||||
->scalarNode('driver')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('mysql')
|
||||
->end()
|
||||
->scalarNode('user')->defaultValue('root')->end()
|
||||
->scalarNode('password')->defaultValue('')->end()
|
||||
->scalarNode('dsn')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('')
|
||||
->end()
|
||||
->scalarNode('classname')->defaultValue($this->debug ? '\Propel\Runtime\Connection\DebugPDO' : '\Propel\Runtime\Connection\ConnectionWrapper')->end()
|
||||
->end()
|
||||
->fixXmlConfig('option')
|
||||
->children()
|
||||
->arrayNode('options')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('attribute')
|
||||
->children()
|
||||
->arrayNode('attributes')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('setting')
|
||||
->children()
|
||||
->arrayNode('settings')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('connection')
|
||||
->append($this->getDbalConnectionsNode())
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a tree configuration for this part of configuration:
|
||||
*
|
||||
* connections:
|
||||
* default:
|
||||
* driver: mysql
|
||||
* user: root
|
||||
* password: null
|
||||
* dsn: xxxxxxxx
|
||||
* classname: PropelPDO
|
||||
* options: {}
|
||||
* attributes: {}
|
||||
* settings: {}
|
||||
*
|
||||
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
|
||||
*/
|
||||
private function getDbalConnectionsNode()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$node = $treeBuilder->root('connections');
|
||||
|
||||
$node
|
||||
->requiresAtLeastOneElement()
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('driver')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('mysql')
|
||||
->end()
|
||||
->scalarNode('user')->defaultValue('root')->end()
|
||||
->scalarNode('password')->defaultValue('')->end()
|
||||
->scalarNode('dsn')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('')
|
||||
->end()
|
||||
->scalarNode('classname')->defaultValue($this->debug ? '\Propel\Runtime\Connection\DebugPDO' : '\Propel\Runtime\Connection\ConnectionWrapper')->end()
|
||||
->arrayNode('slaves')
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('driver')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('mysql')
|
||||
->end()
|
||||
->scalarNode('user')->defaultValue('root')->end()
|
||||
->scalarNode('password')->defaultValue('')->end()
|
||||
->scalarNode('dsn')
|
||||
->beforeNormalization()
|
||||
->always()
|
||||
->then(function ($v) { return str_replace('pdo_', '', $v); })
|
||||
->end()
|
||||
->defaultValue('')
|
||||
->end()
|
||||
->scalarNode('classname')->defaultValue($this->debug ? '\Propel\Runtime\Connection\DebugPDO' : '\Propel\Runtime\Connection\ConnectionWrapper')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('option')
|
||||
->children()
|
||||
->arrayNode('options')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('attribute')
|
||||
->children()
|
||||
->arrayNode('attributes')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
->fixXmlConfig('setting')
|
||||
->children()
|
||||
->arrayNode('settings')
|
||||
->useAttributeAsKey('key')
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue