Skip to content

Commit

Permalink
refactored configuration names
Browse files Browse the repository at this point in the history
How to upgrade (have a look at the skeleton):

  * the "web:config" namespace is now "app:config"

      -    <web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null">
      -        <web:router resource="%kernel.root_dir%/config/routing.xml" />
      -        <web:validation enabled="true" annotations="true" />
      -    </web:config>
      +    <app:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null">
      +        <app:router resource="%kernel.root_dir%/config/routing.xml" />
      +        <app:validation enabled="true" annotations="true" />
      +    </app:config>

  * the "web:templating" namespace is now a sub-namespace of "app:config"

      -    <web:templating
      -        escaping="htmlspecialchars"
      -    />
      +    <app:config>
      +        <app:templating escaping="htmlspecialchars" />
      +    </app:config>

  * the "web:user" namespace is now a sub-namespace of "app:config"

      -    <web:user default-locale="fr">
      -        <web:session name="SYMFONY" type="Native" lifetime="3600" />
      -    </web:user>
      +    <app:config>
      +        <app:user default-locale="fr">
      +            <app:session name="SYMFONY" type="Native" lifetime="3600" />
      +        </app:user>
      +    </app:config>

  * the "web:test" namespace is now a sub-namespace of "app:config"

      -    <web:test />
      +    <app:config error_handler="false">
      +        <app:test />
      +    </app:config>

  * the "swift:mailer" namespace is now "swiftmailer:config"

      -    <swift:mailer
      +    <swiftmailer:config
               transport="smtp"
               encryption="ssl"
               auth_mode="login"

  * the "zend:logger" namespace is now a sub-namespace of "zend:config"

      -    <zend:logger
      -        priority="info"
      -        path="%kernel.logs_dir%/%kernel.environment%.log"
      -    />
      +    <zend:config>
      +        <zend:logger priority="info" path="%kernel.logs_dir%/%kernel.environment%.log" />
      +    </zend:config>
  • Loading branch information
fabpot committed Sep 20, 2010
1 parent 66ddacf commit 2862c6c
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 196 deletions.
Expand Up @@ -19,21 +19,12 @@
*/

/**
* WebExtension.
* FrameworkExtension.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
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.
*
Expand All @@ -45,7 +36,7 @@ public function configLoad($config, ContainerBuilder $container)
$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']) {
Expand All @@ -58,36 +49,6 @@ public function configLoad($config, ContainerBuilder $container)
}
}

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');
Expand All @@ -114,6 +75,30 @@ public function configLoad($config, ContainerBuilder $container)
}
}

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',
Expand Down Expand Up @@ -142,11 +127,13 @@ public function configLoad($config, ContainerBuilder $container)
* @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');
Expand Down Expand Up @@ -228,7 +215,7 @@ public function templatingLoad($config, ContainerBuilder $container)
* @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');
Expand All @@ -240,22 +227,26 @@ public function testLoad($config, ContainerBuilder $container)
* @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]);
}
Expand All @@ -271,6 +262,30 @@ public function sessionLoad($config, ContainerBuilder $container)
}
}

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',
));
}

/*
<profiler only-exceptions="false">
<matcher ip="192.168.0.0/24" path="#/admin/#i" />
Expand Down Expand Up @@ -324,7 +339,7 @@ protected function registerValidationConfiguration($config, ContainerBuilder $co
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();
Expand Down Expand Up @@ -418,6 +433,6 @@ public function getNamespace()

public function getAlias()
{
return 'web';
return 'app';
}
}
Expand Up @@ -6,14 +6,14 @@
elementFormDefault="qualified">

<xsd:element name="config" type="config" />
<xsd:element name="templating" type="templating" />
<xsd:element name="user" type="user" />

<xsd:complexType name="config">
<xsd:sequence>
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
<xsd:element name="validation" type="validation" minOccurs="0" maxOccurs="1" />
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
<xsd:element name="user" type="user" minOccurs="0" maxOccurs="1" />
<xsd:element name="templating" type="templating" minOccurs="0" maxOccurs="1" />
</xsd:sequence>

<xsd:attribute name="ide" type="xsd:string" />
Expand Down
@@ -1,30 +1,25 @@
<?php

$container->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));
Expand All @@ -42,7 +37,7 @@

// Swiftmailer Configuration
/*
$container->loadFromExtension('swift', 'mailer', array(
$container->loadFromExtension('swiftmailer', 'config', array(
'transport' => "smtp",
'encryption' => "ssl",
'auth_mode' => "login",
Expand Down
Expand Up @@ -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),
));
Expand All @@ -12,7 +12,9 @@
'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',
),
));
Expand Up @@ -2,17 +2,16 @@

$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(
'toolbar' => false,
'intercept-redirects' => false,
));

$container->loadFromExtension('zend', 'logger', array(
'priority' => 'debug',
$container->loadFromExtension('zend', 'config', array(
'logger' => array('priority' => 'debug'),
));

$container->loadFromExtension('web', 'test');
Expand Up @@ -2,7 +2,7 @@

<container xmlns="http://www.symfony-project.org/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://www.symfony-project.org/schema/dic/symfony"
xmlns:app="http://www.symfony-project.org/schema/dic/symfony"
xmlns:doctrine="http://www.symfony-project.org/schema/dic/doctrine"
xmlns:twig="http://www.symfony-project.org/schema/dic/twig"
xmlns:swift="http://www.symfony-project.org/schema/dic/swiftmailer"
Expand All @@ -14,14 +14,16 @@
http://www.symfony-project.org/schema/dic/twig http://www.symfony-project.org/schema/dic/twig/twig-1.0.xsd
http://www.symfony-project.org/schema/dic/swiftmailer http://www.symfony-project.org/schema/dic/swiftmailer/swiftmailer-1.0.xsd">

<web:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null">
<web:router resource="%kernel.root_dir%/config/routing.xml" />
<web:validation enabled="true" annotations="true" />
</web:config>

<web:templating
escaping="htmlspecialchars"
/>
<app:config csrf-secret="xxxxxxxxxx" charset="UTF-8" error-handler="null">
<app:router resource="%kernel.root_dir%/config/routing.xml" />
<app:validation enabled="true" annotations="true" />
<app:templating escaping="htmlspecialchars" />
<!--
<app:user default-locale="fr">
<app:session name="SYMFONY" type="Native" lifetime="3600" />
</app:user>
//-->
</app:config>

<!-- Twig Configuration -->
<!--
Expand All @@ -36,7 +38,7 @@

<!-- Swiftmailer Configuration -->
<!--
<swift:mailer
<swiftmailer:config
transport="smtp"
encryption="ssl"
auth_mode="login"
Expand Down
Expand Up @@ -3,7 +3,7 @@
<container xmlns="http://www.symfony-project.org/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:zend="http://www.symfony-project.org/schema/dic/zend"
xmlns:web="http://www.symfony-project.org/schema/dic/symfony"
xmlns:app="http://www.symfony-project.org/schema/dic/symfony"
xmlns:webprofiler="http://www.symfony-project.org/schema/dic/webprofiler"
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
http://www.symfony-project.org/schema/dic/webprofiler http://www.symfony-project.org/schema/dic/webprofiler/webprofiler-1.0.xsd
Expand All @@ -13,18 +13,17 @@
<import resource="config.xml" />
</imports>

<web:config>
<web:router resource="%kernel.root_dir%/config/routing_dev.xml" />
<profiler only-exceptions="false" />
</web:config>
<app:config>
<app:router resource="%kernel.root_dir%/config/routing_dev.xml" />
<app:profiler only-exceptions="false" />
</app:config>

<webprofiler:config
toolbar="true"
intercept-redirects="true"
/>

<zend:logger
priority="info"
path="%kernel.logs_dir%/%kernel.environment%.log"
/>
<zend:config>
<zend:logger priority="info" path="%kernel.logs_dir%/%kernel.environment%.log" />
</zend:config>
</container>

0 comments on commit 2862c6c

Please sign in to comment.