propel-bundle/DependencyInjection/Configuration.php

245 lines
13 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
2016-02-11 19:14:03 +01:00
namespace Propel\Bundle\PropelBundle\DependencyInjection;
use Propel\Common\Config\PropelConfiguration;
2014-09-15 14:25:44 +02:00
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
/**
* This class contains the configuration information for the bundle
*/
class Configuration extends PropelConfiguration
{
2014-09-15 14:25:44 +02:00
private $debug;
private $defaultDir;
2014-09-15 14:25:44 +02:00
public function __construct($debug, $kernelDir)
2014-09-15 14:25:44 +02:00
{
$this->debug = $debug;
$this->defaultDir = $kernelDir.'/propel';
}
protected function addPathsSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('paths')
->addDefaultsIfNotSet()
->children()
->scalarNode('schemaDir')->defaultValue($this->defaultDir)->end()
->scalarNode('sqlDir')->defaultValue($this->defaultDir.'/sql')->end()
->scalarNode('migrationDir')->defaultValue($this->defaultDir.'/migrations')->end()
->scalarNode('composerDir')->defaultNull()->end()
->end()
->end()
->end()
;
2014-09-15 14:25:44 +02:00
}
protected function addRuntimeSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('runtime')
->addDefaultsIfNotSet()
->fixXmlConfig('connection')
->children()
->scalarNode('defaultConnection')->end()
->arrayNode('connections')
->prototype('scalar')->end()
->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->arrayNode('log')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('type')->end()
->scalarNode('path')->end()
->enumNode('level')->values(array(100, 200, 250, 300, 400, 500, 550, 600))->end()
->end()
->end()
->end()
->arrayNode('profiler')
->children()
->scalarNode('classname')->defaultValue('\Propel\Runtime\Util\Profiler')->end()
->floatNode('slowTreshold')->defaultValue(0.1)->end()
->arrayNode('details')
->children()
->arrayNode('time')
->addDefaultsIfNotSet()
->children()
->integerNode('precision')->min(0)->defaultValue(3)->end()
->integerNode('pad')->min(0)->defaultValue(8)->end()
->end()
->end()
->arrayNode('memory')
->addDefaultsIfNotSet()
->children()
->integerNode('precision')->min(0)->defaultValue(3)->end()
->integerNode('pad')->min(0)->defaultValue(8)->end()
->end()
->end()
->arrayNode('memDelta')
->addDefaultsIfNotSet()
->children()
->integerNode('precision')->min(0)->defaultValue(3)->end()
->integerNode('pad')->min(0)->defaultValue(8)->end()
->end()
->end()
->arrayNode('memPeak')
->addDefaultsIfNotSet()
->children()
->integerNode('precision')->min(0)->defaultValue(3)->end()
->integerNode('pad')->min(0)->defaultValue(8)->end()
->end()
->end()
->end()
->end()
->scalarNode('innerGlue')->defaultValue(':')->end()
->scalarNode('outerGlue')->defaultValue('|')->end()
->end()
->end()
->end()
->end() //runtime
->end();
}
2014-09-15 14:25:44 +02:00
protected function addDatabaseSection(ArrayNodeDefinition $node)
{
2014-11-12 16:59:19 +01:00
$validAdapters = array('mysql', 'pgsql', 'sqlite', 'mssql', 'sqlsrv', 'oracle');
2014-09-15 14:25:44 +02:00
$node
->children()
->arrayNode('database')
->isRequired()
->addDefaultsIfNotSet()
->children()
->arrayNode('connections')
->isRequired()
2014-11-04 15:10:43 +01:00
->validate()
->always()
->then(function($connections) {
foreach ($connections as $name => $connection) {
if (strpos($name, '.') !== false) {
throw new \InvalidArgumentException('Dots are not allowed in connection names');
}
}
return $connections;
})
->end()
2014-09-15 14:25:44 +02:00
->requiresAtLeastOneElement()
->normalizeKeys(false)
->useAttributeAsKey('id')
2014-09-15 14:25:44 +02:00
->prototype('array')
->fixXmlConfig('slave')
2016-02-13 18:16:31 +01:00
->fixXmlConfig('model_path')
2014-09-15 14:25:44 +02:00
->children()
->scalarNode('classname')->defaultValue($this->debug ? '\Propel\Runtime\Connection\DebugPDO' : '\Propel\Runtime\Connection\ConnectionWrapper')->end()
2014-11-12 16:59:19 +01:00
->scalarNode('adapter')
2014-09-15 14:25:44 +02:00
->isRequired()
->cannotBeEmpty()
2014-11-12 16:59:19 +01:00
->beforeNormalization()
->ifString()
->then(function ($v) { return preg_replace('/^pdo_/', '', strtolower($v)); })
2014-11-12 16:59:19 +01:00
->end()
->validate()
->ifNotInArray($validAdapters)
->thenInvalid('The adapter %s is not supported. Please choose one of ' . implode(', ', $validAdapters))
->end()
->end()
->scalarNode('dsn')
2014-09-15 14:25:44 +02:00
->isRequired()
->cannotBeEmpty()
2014-11-12 16:59:19 +01:00
->beforeNormalization()
->ifString()
->then(function ($v) { return preg_replace('/^pdo_/', '', $v); })
2014-11-12 16:59:19 +01:00
->end()
2014-09-15 14:25:44 +02:00
->end()
->scalarNode('user')->isRequired()->end()
->scalarNode('password')->isRequired()->treatNullLike('')->end()
->arrayNode('options')
->addDefaultsIfNotSet()
2014-09-15 14:25:44 +02:00
->children()
->booleanNode('ATTR_PERSISTENT')->defaultFalse()->end()
2016-09-07 11:01:25 +02:00
->scalarNode('MYSQL_ATTR_SSL_CA')->end()
->scalarNode('MYSQL_ATTR_SSL_CERT')->end()
->scalarNode('MYSQL_ATTR_SSL_KEY')->end()
->scalarNode('MYSQL_ATTR_MAX_BUFFER_SIZE')->end()
2014-09-15 14:25:44 +02:00
->end()
->end()
->arrayNode('attributes')
->addDefaultsIfNotSet()
2014-09-15 14:25:44 +02:00
->children()
->booleanNode('ATTR_EMULATE_PREPARES')->defaultFalse()->end()
->scalarNode('SQLSRV_ATTR_ENCODING')->end()
2014-09-15 14:25:44 +02:00
->end()
->end()
2016-02-13 18:10:46 +01:00
->arrayNode('model_paths')
->defaultValue(['src', 'vendor'])
->prototype('scalar')->end()
->end()
2014-09-15 14:25:44 +02:00
->arrayNode('settings')
->fixXmlConfig('query', 'queries')
->children()
->scalarNode('charset')->defaultValue('utf8')->end()
->arrayNode('queries')
->prototype('scalar')->end()
->end()
->end()
->end()
->arrayNode('slaves')
->prototype('array')
->children()
->scalarNode('dsn')
->beforeNormalization()
->ifString()
->then(function ($v) { return preg_replace('/^pdo_/', '', $v); })
->end()
->end()
2014-09-15 14:25:44 +02:00
->end()
->end()
->end()
->end()
->end()
->end()
->arrayNode('adapters')
->addDefaultsIfNotSet()
->children()
->arrayNode('mysql')
->addDefaultsIfNotSet()
->children()
->scalarNode('tableType')->defaultValue('InnoDB')->treatNullLike('InnoDB')->end()
->scalarNode('tableEngineKeyword')->defaultValue('ENGINE')->end()
->end()
->end()
->arrayNode('sqlite')
->addDefaultsIfNotSet()
->children()
->scalarNode('foreignKey')->end()
->scalarNode('tableAlteringWorkaround')->end()
->end()
->end()
->arrayNode('oracle')
->addDefaultsIfNotSet()
->children()
->scalarNode('autoincrementSequencePattern')->defaultValue('${table}_SEQ')->end()
->end()
->end()
->end()
->end() //adapters
->end()
->end() //database
->end()
;
}
}