Skip to content

Commit

Permalink
Tweaked the configuration:
Browse files Browse the repository at this point in the history
 - Now we always include the `locales` and `attribute_translator` section in the configuration
 - Removed `%locale%` dependency
  • Loading branch information
boekkooi committed Jun 4, 2016
1 parent 03974d7 commit 66665e8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
12 changes: 12 additions & 0 deletions UPGRADE-2.4.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# UPGRADE FROM 2.3 to 2.4

## Configuration

* The `locale` container parameter was used for the default locale this need to be specified from now on.

After:
```YAML
# app/config/config.yml
be_simple_i18n_routing:
locales:
default_locale: "%locale%"
```
## Routing
* The `I18nRouteCollectionBuilder` class has been removed in favor of `I18nRouteGenerator`.
Expand Down
8 changes: 6 additions & 2 deletions src/DependencyInjection/BeSimpleI18nRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public function load(array $configs, ContainerBuilder $container)
private function configureAttributeTranslator(array $config, ContainerBuilder $container, LoaderInterface $loader)
{
if (!isset($config['attribute_translator'])) {
return;
throw new \InvalidArgumentException('Expected attribute "attribute_translator" to be set');
}

$config = $config['attribute_translator'];
if ($config['type'] === null) {
return;
}

switch ($config['type']) {
case 'service':
Expand Down Expand Up @@ -129,7 +133,7 @@ private function configureDbalCacheDefinition(array $cacheDriver, ContainerBuild
private function configureLocales(array $config, ContainerBuilder $container)
{
if (!isset($config['locales'])) {
return;
throw new \InvalidArgumentException('Expected attribute "locales" to be set');
}
$config = $config['locales'];

Expand Down
4 changes: 3 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private function addLocalesSection(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->arrayNode('locales')
->addDefaultsIfNotSet()
->children()
->scalarNode('default_locale')->defaultNull()->end()
->arrayNode('supported')
Expand Down Expand Up @@ -86,9 +87,10 @@ private function addAttributeTranslatorSection(ArrayNodeDefinition $rootNode)
$rootNode
->children()
->arrayNode('attribute_translator')
->canBeEnabled()
->children()
->enumNode('type')
->isRequired()
->defaultValue('translator')
->values(array('service', 'doctrine_dbal', 'translator'))
->end()
->scalarNode('id')->end()
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="be_simple_i18n_routing.default_locale">%locale%</parameter>
<parameter key="be_simple_i18n_routing.locales" type="collection" />

<parameter key="be_simple_i18n_routing.router.class">BeSimple\I18nRoutingBundle\Routing\Router</parameter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ protected function getContainerExtensions()
*/
public function loading_with_default_values()
{
$this->container->setParameter('locale', null);

$this->load();

$this->assertContainerBuilderHasService('be_simple_i18n_routing.router');
Expand All @@ -44,7 +42,7 @@ public function loading_with_default_values()
$this->assertContainerBuilderHasService('be_simple_i18n_routing.route_name_inflector.postfix');
$this->assertContainerBuilderHasService('be_simple_i18n_routing.route_generator');

$this->assertContainerBuilderHasParameter('be_simple_i18n_routing.default_locale', '%locale%');
$this->assertContainerBuilderHasParameter('be_simple_i18n_routing.default_locale', null);
$this->assertContainerBuilderHasParameter('be_simple_i18n_routing.locales', array());

$this->assertContainerBuilderHasParameter('be_simple_i18n_routing.router.class', 'BeSimple\I18nRoutingBundle\Routing\Router');
Expand Down
16 changes: 16 additions & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ public function processed_configuration_defaults()
array(
'annotations' => false,
'route_name_inflector' => 'be_simple_i18n_routing.route_name_inflector.postfix',
'locales' => array(
'default_locale' => null,
'supported' => array(),
'filter' => false,
'strict' => false
),
'attribute_translator' => array(
'enabled' => false,
'type' => 'translator',
'connection' => null,
'cache' => array(
'type' => 'array',
)
)
)
);
}
Expand All @@ -41,6 +55,7 @@ public function processed_configuration_for_attribute_translator_service_default
),
array(
'attribute_translator' => array(
'enabled' => true,
'type' => 'service',
'id' => 'test_service_id',
'connection' => null,
Expand Down Expand Up @@ -85,6 +100,7 @@ public function processed_configuration_for_attribute_translator_doctrine_dbal_d
),
array(
'attribute_translator' => array(
'enabled' => true,
'type' => 'doctrine_dbal',
'connection' => null,
'cache' => array(
Expand Down

0 comments on commit 66665e8

Please sign in to comment.