From 2862c6cce41a3af2d9a6d64502246ea072de0b5a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 20 Sep 2010 21:01:41 +0200 Subject: [PATCH] refactored configuration names How to upgrade (have a look at the skeleton): * the "web:config" namespace is now "app:config" - - - - + + + + * the "web:templating" namespace is now a sub-namespace of "app:config" - + + + * the "web:user" namespace is now a sub-namespace of "app:config" - - - + + + + + * the "web:test" namespace is now a sub-namespace of "app:config" - + + + * the "swift:mailer" namespace is now "swiftmailer:config" - + + + --- ...ebExtension.php => FrameworkExtension.php} | 117 ++++++++++-------- .../Resources/config/schema/symfony-1.0.xsd | 4 +- .../application/php/config/config.php | 33 +++-- .../application/php/config/config_dev.php | 10 +- .../application/php/config/config_test.php | 9 +- .../application/xml/config/config.xml | 22 ++-- .../application/xml/config/config_dev.xml | 17 ++- .../application/xml/config/config_test.xml | 16 ++- .../application/yml/config/config.yml | 17 ++- .../application/yml/config/config_dev.yml | 9 +- .../application/yml/config/config_test.yml | 10 +- ...ionTest.php => FrameworkExtensionTest.php} | 25 ++-- .../SwiftmailerExtension.php | 14 +-- .../SwiftmailerExtensionTest.php | 8 +- .../DependencyInjection/ZendExtension.php | 38 ++++-- .../Resources/config/schema/zend-1.0.xsd | 56 +++++---- .../DependencyInjection/ZendExtensionTest.php | 18 ++- 17 files changed, 227 insertions(+), 196 deletions(-) rename src/Symfony/Bundle/FrameworkBundle/DependencyInjection/{WebExtension.php => FrameworkExtension.php} (86%) rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/{WebExtensionTest.php => FrameworkExtensionTest.php} (83%) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php similarity index 86% rename from src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php rename to src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index fdd6a1b7d5..1d0ba8a309 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/WebExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -19,21 +19,12 @@ use Symfony\Component\DependencyInjection\Definition; */ /** - * WebExtension. + * FrameworkExtension. * * @author Fabien Potencier */ -class WebExtension extends Extension +class FrameworkExtension extends Extension { - protected $resources = array( - 'templating' => 'templating.xml', - 'web' => 'web.xml', - 'routing' => 'routing.xml', - // validation.xml conflicts with the naming convention for XML - // validation mapping files, so call it validator.xml - 'validation' => 'validator.xml', - ); - /** * Loads the web configuration. * @@ -45,7 +36,7 @@ class WebExtension extends Extension $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config'); if (!$container->hasDefinition('controller_manager')) { - $loader->load($this->resources['web']); + $loader->load('web.xml'); } if (isset($config['ide']) && 'textmate' === $config['ide']) { @@ -58,36 +49,6 @@ class WebExtension extends Extension } } - if (isset($config['router'])) { - if (!$container->hasDefinition('router')) { - $loader->load($this->resources['routing']); - } - - $container->setParameter('routing.resource', $config['router']['resource']); - - $this->addCompiledClasses($container, array( - 'Symfony\\Component\\Routing\\RouterInterface', - 'Symfony\\Component\\Routing\\Router', - 'Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface', - 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', - 'Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface', - 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', - 'Symfony\\Component\\Routing\\Loader\\Loader', - 'Symfony\\Component\\Routing\\Loader\\DelegatingLoader', - 'Symfony\\Component\\Routing\\Loader\\LoaderResolver', - 'Symfony\\Bundle\\FrameworkBundle\\Routing\\LoaderResolver', - 'Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader', - )); - } - - if (isset($config['profiler'])) { - $this->registerProfilerConfiguration($config, $container); - } - - if (isset($config['validation']['enabled'])) { - $this->registerValidationConfiguration($config, $container); - } - if (!$container->hasDefinition('event_dispatcher')) { $loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); $loader->load('services.xml'); @@ -114,6 +75,30 @@ class WebExtension extends Extension } } + if (isset($config['router'])) { + $this->registerRouterConfiguration($config, $container); + } + + if (isset($config['profiler'])) { + $this->registerProfilerConfiguration($config, $container); + } + + if (isset($config['validation']['enabled'])) { + $this->registerValidationConfiguration($config, $container); + } + + if (isset($config['templating'])) { + $this->registerTemplatingConfiguration($config, $container); + } + + if (isset($config['test'])) { + $this->registerTestConfiguration($config, $container); + } + + if (isset($config['user'])) { + $this->registerUserConfiguration($config, $container); + } + $this->addCompiledClasses($container, array( 'Symfony\\Component\\HttpFoundation\\ParameterBag', 'Symfony\\Component\\HttpFoundation\\HeaderBag', @@ -142,11 +127,13 @@ class WebExtension extends Extension * @param array $config An array of configuration settings * @param ContainerBuilder $container A ContainerBuilder instance */ - public function templatingLoad($config, ContainerBuilder $container) + protected function registerTemplatingConfiguration($config, ContainerBuilder $container) { + $config = $config['templating']; + if (!$container->hasDefinition('templating')) { $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config'); - $loader->load($this->resources['templating']); + $loader->load('templating.xml'); if ($container->getParameter('kernel.debug')) { $loader->load('templating_debug.xml'); @@ -228,7 +215,7 @@ class WebExtension extends Extension * @param array $config A configuration array * @param ContainerBuilder $container A ContainerBuilder instance */ - public function testLoad($config, ContainerBuilder $container) + protected function registerTestConfiguration($config, ContainerBuilder $container) { $loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); $loader->load('test.xml'); @@ -240,22 +227,26 @@ class WebExtension extends Extension * @param array $config A configuration array * @param ContainerBuilder $container A ContainerBuilder instance */ - public function sessionLoad($config, ContainerBuilder $container) + protected function registerUserConfiguration($config, ContainerBuilder $container) { + $config = $config['user']; + if (!$container->hasDefinition('session')) { $loader = new XmlFileLoader($container, array(__DIR__.'/../Resources/config', __DIR__.'/Resources/config')); $loader->load('session.xml'); } - if (isset($config['default_locale'])) { - $container->setParameter('session.default_locale', $config['default_locale']); + foreach (array('default_locale', 'default-locale') as $key) { + if (isset($config[$key])) { + $container->setParameter('session.default_locale', $config[$key]); + } } if (isset($config['class'])) { $container->setParameter('session.class', $config['class']); } - foreach (array('name', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) { + foreach (array('name', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'cache-limiter', 'pdo.db_table') as $name) { if (isset($config['session'][$name])) { $container->setParameter('session.options.'.$name, $config['session'][$name]); } @@ -271,6 +262,30 @@ class WebExtension extends Extension } } + protected function registerRouterConfiguration($config, ContainerBuilder $container) + { + if (!$container->hasDefinition('router')) { + $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config'); + $loader->load('routing.xml'); + } + + $container->setParameter('routing.resource', $config['router']['resource']); + + $this->addCompiledClasses($container, array( + 'Symfony\\Component\\Routing\\RouterInterface', + 'Symfony\\Component\\Routing\\Router', + 'Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface', + 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', + 'Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface', + 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', + 'Symfony\\Component\\Routing\\Loader\\Loader', + 'Symfony\\Component\\Routing\\Loader\\DelegatingLoader', + 'Symfony\\Component\\Routing\\Loader\\LoaderResolver', + 'Symfony\\Bundle\\FrameworkBundle\\Routing\\LoaderResolver', + 'Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader', + )); + } + /* @@ -324,7 +339,7 @@ class WebExtension extends Extension if ($config['validation']['enabled']) { if (!$container->hasDefinition('validator')) { $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config'); - $loader->load($this->resources['validation']); + $loader->load('validator.xml'); } $xmlMappingFiles = array(); @@ -418,6 +433,6 @@ class WebExtension extends Extension public function getAlias() { - return 'web'; + return 'app'; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 2527bf56b4..1f5eeaf7bd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -6,14 +6,14 @@ elementFormDefault="qualified"> - - + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config.php b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config.php index dc5befdc5a..934d400a12 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config.php @@ -1,30 +1,25 @@ loadFromExtension('web', 'config', array( +$container->loadFromExtension('app', 'config', array( 'charset' => 'UTF-8', 'error_handler' => null, 'csrf-secret' => 'xxxxxxxxxx', 'router' => array('resource' => '%kernel.root_dir%/config/routing.php'), 'validation' => array('enabled' => true, 'annotations' => true), + 'templating' => array( + 'escaping' => 'htmlspecialchars' + #'assets_version' => "SomeVersionScheme", + ), + #'user' => array( + # 'default_locale' => "fr", + # 'session' => array( + # 'name' => "SYMFONY", + # 'type' => "Native", + # 'lifetime' => "3600", + # ) + #), )); -$container->loadFromExtension('web', 'templating', array( - 'escaping' => "htmlspecialchars", -# 'assets_version' => "SomeVersionScheme", -)); - -// Sessions -/* -$container->loadFromExtension('kernel', 'session', array( - 'default_locale' => "fr", - 'session' => array( - 'name' => "SYMFONY", - 'type' => "Native", - 'lifetime' => "3600", - ) -)); -*/ - // Twig Configuration /* $container->loadFromExtension('twig', 'config', array('auto_reload' => true)); @@ -42,7 +37,7 @@ $container->loadFromExtension('doctrine', 'orm'); // Swiftmailer Configuration /* -$container->loadFromExtension('swift', 'mailer', array( +$container->loadFromExtension('swiftmailer', 'config', array( 'transport' => "smtp", 'encryption' => "ssl", 'auth_mode' => "login", diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_dev.php b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_dev.php index fa76445d1d..81b10922ee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_dev.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_dev.php @@ -2,7 +2,7 @@ $loader->import('config.php'); -$container->loadFromExtension('web', 'config', array( +$container->loadFromExtension('app', 'config', array( 'router' => array('resource' => '%kernel.root_dir%/config/routing_dev.php'), 'profiler' => array('only-exceptions' => false), )); @@ -12,7 +12,9 @@ $container->loadFromExtension('webprofiler', 'config', array( 'intercept-redirects' => true, )); -$container->loadFromExtension('zend', 'logger', array( - 'priority' => 'info', - 'path' => '%kernel.logs_dir%/%kernel.environment%.log', +$container->loadFromExtension('zend', 'config', array( + 'logger' => array( + 'priority' => 'info', + 'path' => '%kernel.logs_dir%/%kernel.environment%.log', + ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_test.php b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_test.php index 7325b33925..aa671ab6d1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_test.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/php/config/config_test.php @@ -2,8 +2,9 @@ $loader->import('config_dev.php'); -$container->loadFromExtension('web', 'config', array( +$container->loadFromExtension('app', 'config', array( 'error_handler' => false, + 'test' => true, )); $container->loadFromExtension('webprofiler', 'config', array( @@ -11,8 +12,6 @@ $container->loadFromExtension('webprofiler', 'config', array( 'intercept-redirects' => false, )); -$container->loadFromExtension('zend', 'logger', array( - 'priority' => 'debug', +$container->loadFromExtension('zend', 'config', array( + 'logger' => array('priority' => 'debug'), )); - -$container->loadFromExtension('web', 'test'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/xml/config/config.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/xml/config/config.xml index a8a1aafed6..02f21671bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/xml/config/config.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/application/xml/config/config.xml @@ -2,7 +2,7 @@ - - - - - - + + + + + +