refactored configuration names

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>
This commit is contained in:
Fabien Potencier 2010-09-20 21:01:41 +02:00
parent 66ddacf2e5
commit 2862c6cce4
17 changed files with 227 additions and 196 deletions

View File

@ -19,21 +19,12 @@ use Symfony\Component\DependencyInjection\Definition;
*/
/**
* 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.
*
@ -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',
));
}
/*
<profiler only-exceptions="false">
<matcher ip="192.168.0.0/24" path="#/admin/#i" />
@ -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';
}
}

View File

@ -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" />

View File

@ -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));
@ -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",

View File

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

View File

@ -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');

View File

@ -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"
@ -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 -->
<!--
@ -36,7 +38,7 @@
<!-- Swiftmailer Configuration -->
<!--
<swift:mailer
<swiftmailer:config
transport="smtp"
encryption="ssl"
auth_mode="login"

View File

@ -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
@ -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>

View File

@ -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"
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/zend http://www.symfony-project.org/schema/dic/zend/zend-1.0.xsd">
@ -16,13 +16,11 @@
intercept-redirects="false"
/>
<web:config
error_handler="false"
/>
<app:config error_handler="false">
<app:test />
</app:config>
<zend:logger
priority="debug"
/>
<web:test />
<zend:config>
<zend:logger priority="debug" />
</zend:config>
</container>

View File

@ -1,13 +1,18 @@
web.config:
app.config:
charset: UTF-8
error_handler: null
csrf_secret: xxxxxxxxxx
router: { resource: "%kernel.root_dir%/config/routing.yml" }
validation: { enabled: true, annotations: true }
web.templating:
escaping: htmlspecialchars
#assets_version: SomeVersionScheme
templating:
escaping: htmlspecialchars
#assets_version: SomeVersionScheme
#user:
# default_locale: fr
# session:
# name: SYMFONY
# type: Native
# lifetime: 3600
## Twig Configuration
#twig.config:
@ -21,7 +26,7 @@ web.templating:
#doctrine.orm: ~
## Swiftmailer Configuration
#swift.mailer:
#swiftmailer.config:
# transport: smtp
# encryption: ssl
# auth_mode: login

View File

@ -1,7 +1,7 @@
imports:
- { resource: config.yml }
web.config:
app.config:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
@ -9,6 +9,7 @@ webprofiler.config:
toolbar: true
intercept_redirects: true
zend.logger:
priority: debug
path: %kernel.root_dir%/logs/%kernel.environment%.log
zend.config:
logger:
priority: debug
path: %kernel.root_dir%/logs/%kernel.environment%.log

View File

@ -1,14 +1,14 @@
imports:
- { resource: config_dev.yml }
web.config:
app.config:
error_handler: false
test: ~
webprofiler.config:
toolbar: false
intercept_redirects: false
zend.logger:
priority: debug
web.test: ~
zend.config:
logger:
priority: debug

View File

@ -12,41 +12,32 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\WebExtension;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class WebExtensionTest extends TestCase
class FrameworkExtensionTest extends TestCase
{
public function testConfigLoad()
{
$container = $this->getContainer();
$loader = new WebExtension();
$loader = new FrameworkExtension();
$loader->configLoad(array(), $container);
$this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\RequestListener', $container->getParameter('request_listener.class'), '->webLoad() loads the web.xml file if not already loaded');
$container = $this->getContainer();
$loader = new WebExtension();
$loader = new FrameworkExtension();
// profiler
$loader->configLoad(array('profiler' => true), $container);
$this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\Profiler', $container->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded');
}
public function testTemplatingLoad()
{
$container = $this->getContainer();
$loader = new WebExtension();
$loader->templatingLoad(array(), $container);
// templating
$loader->configLoad(array('templating' => array()), $container);
$this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\Templating\\Engine', $container->getParameter('templating.engine.class'), '->templatingLoad() loads the templating.xml file if not already loaded');
}
public function testValidationLoad()
{
$container = $this->getContainer();
$loader = new WebExtension();
// validation
$loader->configLoad(array('validation' => array('enabled' => true)), $container);
$this->assertEquals('Symfony\Component\Validator\Validator', $container->getParameter('validator.class'), '->validationLoad() loads the validation.xml file if not already loaded');
$this->assertFalse($container->hasDefinition('validator.mapping.loader.annotation_loader'), '->validationLoad() doesn\'t load the annotations service unless its needed');

View File

@ -32,16 +32,16 @@ class SwiftMailerExtension extends Extension
*
* Usage example:
*
* <swift:mailer transport="gmail" delivery_strategy="spool">
* <swift:username>fabien</swift:username>
* <swift:password>xxxxx</swift:password>
* <swift:spool path="/path/to/spool/" />
* </swift:mailer>
* <swiftmailer:config transport="gmail" delivery_strategy="spool">
* <swiftmailer:username>fabien</swift:username>
* <swiftmailer:password>xxxxx</swift:password>
* <swiftmailer:spool path="/path/to/spool/" />
* </swiftmailer:config>
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function mailerLoad($config, ContainerBuilder $container)
public function configLoad($config, ContainerBuilder $container)
{
if (!$container->hasDefinition('swiftmailer.mailer')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
@ -134,6 +134,6 @@ class SwiftMailerExtension extends Extension
*/
public function getAlias()
{
return 'swift';
return 'swiftmailer';
}
}

View File

@ -17,17 +17,17 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
class SwiftmailerExtensionTest extends TestCase
{
public function testMailerLoad()
public function testConfigLoad()
{
$container = new ContainerBuilder();
$loader = new SwiftmailerExtension();
$loader->mailerLoad(array(), $container);
$loader->configLoad(array(), $container);
$this->assertEquals('Swift_Mailer', $container->getParameter('swiftmailer.class'), '->mailerLoad() loads the swiftmailer.xml file if not already loaded');
$loader->mailerLoad(array('transport' => 'sendmail'), $container);
$loader->configLoad(array('transport' => 'sendmail'), $container);
$this->assertEquals('sendmail', $container->getParameter('swiftmailer.transport.name'), '->mailerLoad() overrides existing configuration options');
$loader->mailerLoad(array(), $container);
$loader->configLoad(array(), $container);
$this->assertEquals('sendmail', $container->getParameter('swiftmailer.transport.name'), '->mailerLoad() overrides existing configuration options');
}
}

View File

@ -22,10 +22,28 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
*/
class ZendExtension extends Extension
{
protected $resources = array(
'logger' => 'logger.xml',
'i18n' => 'i18n.xml',
);
/**
* Loads the Zend Framework configuration.
*
* Usage example:
*
* <zend:config>
* <zend:logger priority="info" path="/path/to/some.log" />
* </zend:config>
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function configLoad($config, ContainerBuilder $container)
{
if (isset($config['logger'])) {
$this->registerLoggerConfiguration($config, $container);
}
if (isset($config['i18n'])) {
$this->registerI18nConfiguration($config, $container);
}
}
/**
* Loads the logger configuration.
@ -37,11 +55,13 @@ class ZendExtension extends Extension
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function loggerLoad($config, ContainerBuilder $container)
protected function registerLoggerConfiguration($config, ContainerBuilder $container)
{
$config = $config['logger'];
if (!$container->hasDefinition('zend.logger')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
$loader->load($this->resources['logger']);
$loader->load('logger.xml');
$container->setAlias('logger', 'zend.logger');
}
@ -74,11 +94,13 @@ class ZendExtension extends Extension
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
public function i18nLoad($config, ContainerBuilder $container)
protected function registerI18nConfiguration($config, ContainerBuilder $container)
{
$config = $config['i18n'];
if (!$container->hasDefinition('zend.i18n')) {
$loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
$loader->load($this->resources['i18n']);
$loader->load('i18n.xml');
$container->setAlias('i18n', 'zend.i18n');
}

View File

@ -5,32 +5,38 @@
targetNamespace="http://www.symfony-project.org/schema/dic/zend"
elementFormDefault="qualified">
<xsd:element name="logger" type="logger" />
<xsd:element name="config" type="config" />
<xsd:complexType name="logger">
<xsd:attribute name="priority" type="priority" />
<xsd:attribute name="path" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="config">
<xsd:sequence>
<xsd:element name="logger" type="logger" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="priority">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="emerg" />
<xsd:enumeration value="alert" />
<xsd:enumeration value="crit" />
<xsd:enumeration value="err" />
<xsd:enumeration value="warn" />
<xsd:enumeration value="notice" />
<xsd:enumeration value="info" />
<xsd:enumeration value="debug" />
<xsd:complexType name="logger">
<xsd:attribute name="priority" type="priority" />
<xsd:attribute name="path" type="xsd:string" />
</xsd:complexType>
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="3" />
<xsd:enumeration value="4" />
<xsd:enumeration value="5" />
<xsd:enumeration value="6" />
<xsd:enumeration value="7" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="priority">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="emerg" />
<xsd:enumeration value="alert" />
<xsd:enumeration value="crit" />
<xsd:enumeration value="err" />
<xsd:enumeration value="warn" />
<xsd:enumeration value="notice" />
<xsd:enumeration value="info" />
<xsd:enumeration value="debug" />
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="3" />
<xsd:enumeration value="4" />
<xsd:enumeration value="5" />
<xsd:enumeration value="6" />
<xsd:enumeration value="7" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

View File

@ -17,27 +17,23 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
class ZendExtensionTest extends TestCase
{
public function testLoggerLoad()
public function testConfigLoad()
{
// logger
$container = new ContainerBuilder();
$loader = new ZendExtension();
$loader->loggerLoad(array(), $container);
$loader->configLoad(array('logger' => array()), $container);
$this->assertEquals('Symfony\\Bundle\\ZendBundle\\Logger\\Logger', $container->getParameter('zend.logger.class'), '->loggerLoad() loads the logger.xml file if not already loaded');
$loader->loggerLoad(array('priority' => 3), $container);
$loader->configLoad(array('logger' => array('priority' => 3)), $container);
$this->assertEquals(3, $container->getParameter('zend.logger.priority'), '->loggerLoad() overrides existing configuration options');
}
public function testI18nLoad()
{
$container = new ContainerBuilder();
$loader = new ZendExtension();
$loader->i18nLoad(array(), $container);
// i18n
$loader->configLoad(array('i18n' => array()), $container);
$this->assertEquals('Zend\\Translator\\Translator', $container->getParameter('zend.translator.class'), '->i&8nLoad() loads the i18n.xml file if not already loaded');
$loader->i18nLoad(array('adapter' => 'Zend\\Translator\\Translator::AN_XLIFF', 'locale' => 'fr'), $container);
$loader->configLoad(array('i18n' => array('adapter' => 'Zend\\Translator\\Translator::AN_XLIFF', 'locale' => 'fr')), $container);
$this->assertEquals('Xliff', $container->getParameter('zend.translator.adapter'), '->i18nLoad() overrides existing configuration options');
$this->assertEquals('fr', $container->getParameter('zend.translator.locale'), '->i18nLoad() overrides existing configuration options');
}