Skip to content

Commit

Permalink
[FrameworkBundle] re-introduced parameters in the DIC for better over…
Browse files Browse the repository at this point in the history
…ridability
  • Loading branch information
fabpot committed May 13, 2011
1 parent 05a946b commit f7aea2a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 84 deletions.
Expand Up @@ -60,14 +60,11 @@ public function load(array $configs, ContainerBuilder $container)
$config = $processor->processConfiguration($configuration, $configs);

$container->setParameter('kernel.cache_warmup', $config['cache_warmer']);

if (isset($config['charset'])) {
$container->setParameter('kernel.charset', $config['charset']);
}

$container->setParameter('kernel.secret', $config['secret']);

$container->getDefinition('exception_listener')->replaceArgument(0, $config['exception_controller']);
$container->setParameter('exception_listener.controller', $config['exception_controller']);

if (!empty($config['test'])) {
$loader->load('test.xml');
Expand Down Expand Up @@ -145,11 +142,8 @@ public function load(array $configs, ContainerBuilder $container)
*/
private function registerCsrfProtectionConfiguration(array $config, ContainerBuilder $container)
{
$container
->getDefinition('form.type_extension.csrf')
->replaceArgument(0, $config['enabled'])
->replaceArgument(1, $config['field_name'])
;
$container->setParameter('form.type_extension.csrf.enabled', $config['enabled']);
$container->setParameter('form.type_extension.csrf.field_name', $config['field_name']);
}

/**
Expand Down Expand Up @@ -177,10 +171,8 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
$loader->load('profiling.xml');
$loader->load('collectors.xml');

$container->getDefinition('profiler_listener')
->replaceArgument(2, $config['only_exceptions'])
->replaceArgument(3, $config['only_master_requests'])
;
$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);

// Choose storage class based on the DSN
$supported = array(
Expand All @@ -192,13 +184,12 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
}

$container->getDefinition('profiler.storage')
->replaceArgument(0, $config['dsn'])
->replaceArgument(1, $config['username'])
->replaceArgument(2, $config['password'])
->replaceArgument(3, $config['lifetime'])
->setClass($supported[$class])
;
$container->setParameter('profiler.storage.dsn', $config['dsn']);
$container->setParameter('profiler.storage.username', $config['username']);
$container->setParameter('profiler.storage.password', $config['password']);
$container->setParameter('profiler.storage.lifetime', $config['lifetime']);

$container->getDefinition('profiler.storage')->setClass($supported[$class]);

if (isset($config['matcher'])) {
if (isset($config['matcher']['service'])) {
Expand Down Expand Up @@ -229,8 +220,8 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
{
$loader->load('routing.xml');

$container->setParameter('router.resource', $config['resource']);
$router = $container->findDefinition('router.real');
$router->replaceArgument(1, $config['resource']);

if (isset($config['type'])) {
$argument = $router->getArgument(2);
Expand All @@ -243,9 +234,8 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
$container->setAlias('router', 'router.cached');
}

$def = $container->getDefinition('request_listener');
$def->replaceArgument(2, $config['http_port']);
$def->replaceArgument(3, $config['https_port']);
$container->setParameter('request_listener.http_port', $config['http_port']);
$container->setParameter('request_listener.https_port', $config['https_port']);

$this->addClassesToCompile(array(
'Symfony\\Component\\Routing\\RouterInterface',
Expand Down Expand Up @@ -273,7 +263,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
if (!empty($config['auto_start'])) {
$session->addMethodCall('start');
}
$session->replaceArgument(1, $config['default_locale']);
$container->setParameter('session.default_locale', $config['default_locale']);

// session storage
$container->setAlias('session.storage', $config['storage_id']);
Expand Down Expand Up @@ -315,10 +305,7 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
'macvim' => 'mvim://open?url=file://%f&line=%l',
);

$container
->getDefinition('templating.helper.code')
->replaceArgument(0, str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide))
;
$container->setParameter('templating.helper.code.file_link_format', str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide));

if ($container->getParameter('kernel.debug')) {
$loader->load('templating_debug.xml');
Expand All @@ -331,12 +318,10 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
$package['version'],
));
}
$container
->getDefinition('templating.helper.assets')
->replaceArgument(1, isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array())
->replaceArgument(2, $config['assets_version'])
->replaceArgument(3, $packages)
;

$container->setParameter('templating.helper.assets.assets_base_urls', isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array());
$container->setParameter('templating.helper.assets.assets_version', $config['assets_version']);
$container->setParameter('templating.helper.assets.packages', $packages);

if (!empty($config['loaders'])) {
$loaders = array_map(function($loader) { return new Reference($loader); }, $config['loaders']);
Expand All @@ -350,11 +335,12 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB
}
}

$container->setParameter('templating.loader.cache.path', null);
if (isset($config['cache'])) {
// Wrap the existing loader with cache (must happen after loaders are registered)
$container->setDefinition('templating.loader.wrapped', $container->findDefinition('templating.loader'));
$loaderCache = $container->getDefinition('templating.loader.cache');
$loaderCache->replaceArgument(1, $config['cache']);
$container->setParameter('templating.loader.cache.path', $config['cache']);

$container->setDefinition('templating.loader', $loaderCache);
}
Expand Down Expand Up @@ -459,15 +445,8 @@ private function registerValidationConfiguration(array $config, ContainerBuilder

$loader->load('validator.xml');

$container
->getDefinition('validator.mapping.loader.xml_files_loader')
->replaceArgument(0, $this->getValidatorXmlMappingFiles($container))
;

$container
->getDefinition('validator.mapping.loader.yaml_files_loader')
->replaceArgument(0, $this->getValidatorYamlMappingFiles($container))
;
$container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $this->getValidatorXmlMappingFiles($container));
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $this->getValidatorYamlMappingFiles($container));

if (isset($config['annotations'])) {
$namespaces = array('assert' => 'Symfony\\Component\\Validator\\Constraints\\');
Expand All @@ -477,10 +456,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
}

// Register annotation loader
$container
->getDefinition('validator.mapping.loader.annotation_loader')
->replaceArgument(0, $namespaces)
;
$container->setParameter('validator.mapping.loader.annotation_loader.namespaces', $namespaces);

$loaderChain = $container->getDefinition('validator.mapping.loader.loader_chain');
$arguments = $loaderChain->getArguments();
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Expand Up @@ -159,8 +159,8 @@
</service>
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
<tag name="form.type_extension" alias="form" />
<argument /> <!-- enabled -->
<argument /> <!-- field_name -->
<argument>%form.type_extension.csrf.enabled%</argument>
<argument>%form.type_extension.csrf.field_name%</argument>
</service>
</services>
</container>
Expand Up @@ -17,10 +17,10 @@
</service>

<service id="profiler.storage" class="" public="false">
<argument /> <!-- DSN -->
<argument /> <!-- Username -->
<argument /> <!-- Password -->
<argument /> <!-- Lifetime -->
<argument>%profiler.storage.dsn%</argument>
<argument>%profiler.storage.username%</argument>
<argument>%profiler.storage.password%</argument>
<argument>%profiler.storage.lifetime%</argument>
</service>

<service id="profiler_listener" class="%profiler_listener.class%">
Expand All @@ -29,8 +29,8 @@
<tag name="kernel.listener" event="onCoreRequest" />
<argument type="service" id="service_container" />
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
<argument /> <!-- Only exceptions? -->
<argument /> <!-- Only master requests? -->
<argument>%profiler_listener.only_exceptions%</argument>
<argument>%profiler_listener.only_master_requests%</argument>
</service>
</services>
</container>
Expand Up @@ -55,7 +55,7 @@

<service id="router.real" class="%router.class%">
<argument type="service" id="routing.loader" />
<argument /> <!-- routing resource -->
<argument>%router.resource%</argument>
<argument type="collection">
<argument key="cache_dir">%kernel.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>
Expand Down
Expand Up @@ -13,7 +13,7 @@
<services>
<service id="session" class="%session.class%">
<argument type="service" id="session.storage" />
<argument /> <!-- default locale -->
<argument>%session.default_locale%</argument>
</service>

<service id="session.storage.native" class="%session.storage.native.class%" public="false">
Expand Down
Expand Up @@ -19,7 +19,7 @@
<services>
<service id="templating.engine.delegating" class="%templating.engine.delegating.class%" public="false">
<argument type="service" id="service_container" />
<argument type="collection" />
<argument /> <!-- engines -->
</service>

<service id="templating.name_parser" class="%templating.name_parser.class%">
Expand Down Expand Up @@ -52,7 +52,7 @@

<service id="templating.loader.cache" class="%templating.loader.cache.class%" public="false">
<argument type="service" id="templating.loader.wrapped" />
<argument /> <!-- cache path -->
<argument>%templating.loader.cache.path%</argument>
<call method="setDebugger"><argument type="service" id="templating.debugger" on-invalid="ignore" /></call>
</service>

Expand Down
Expand Up @@ -35,9 +35,9 @@
<service id="templating.helper.assets" class="%templating.helper.assets.class%">
<tag name="templating.helper" alias="assets" />
<argument type="service" id="request" strict="false" />
<argument type="collection" /> <!-- assets base URLs -->
<argument /> <!-- assets version -->
<argument type="collection" /> <!-- packages -->
<argument>%templating.helper.assets.assets_base_urls%</argument>
<argument>%templating.helper.assets.assets_version%</argument>
<argument>%templating.helper.assets.packages%</argument>
</service>

<service id="templating.helper.request" class="%templating.helper.request.class%">
Expand All @@ -62,7 +62,7 @@

<service id="templating.helper.code" class="%templating.helper.code.class%">
<tag name="templating.helper" alias="code" />
<argument /> <!-- file link format -->
<argument>%templating.helper.code.file_link_format%</argument>
<argument>%kernel.root_dir%</argument>
</service>

Expand Down
Expand Up @@ -48,15 +48,15 @@
<service id="validator.mapping.loader.static_method_loader" class="%validator.mapping.loader.static_method_loader.class%" public="false" />

<service id="validator.mapping.loader.annotation_loader" class="%validator.mapping.loader.annotation_loader.class%" public="false">
<argument /> <!-- namespaces -->
<argument type="collection">%validator.mapping.loader.annotation_loader.namespaces%</argument>
</service>

<service id="validator.mapping.loader.xml_files_loader" class="%validator.mapping.loader.xml_files_loader.class%" public="false">
<argument /> <!-- mapping files -->
<argument type="collection">%validator.mapping.loader.xml_files_loader.mapping_files%</argument>
</service>

<service id="validator.mapping.loader.yaml_files_loader" class="%validator.mapping.loader.yaml_files_loader.class%" public="false">
<argument /> <!-- mapping files -->
<argument type="collection">%validator.mapping.loader.yaml_files_loader.mapping_files%</argument>
</service>
</services>
</container>
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
Expand Up @@ -31,8 +31,8 @@
<tag name="monolog.logger" channel="request" />
<argument type="service" id="service_container" />
<argument type="service" id="router" />
<argument /> <!-- HTTP port -->
<argument /> <!-- HTTPS port -->
<argument>%request_listener.http_port%</argument>
<argument>%request_listener.https_port%</argument>
<argument type="service" id="logger" on-invalid="ignore" />
</service>

Expand All @@ -44,7 +44,7 @@
<service id="exception_listener" class="%exception_listener.class%">
<tag name="kernel.listener" event="onCoreException" priority="-128" />
<tag name="monolog.logger" channel="request" />
<argument /> <!-- controller name -->
<argument>%exception_listener.controller%</argument>
<argument type="service" id="logger" on-invalid="null" />
</service>
</services>
Expand Down

3 comments on commit f7aea2a

@lsmith77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is overriding Bundle parameters now a supported extension point?
If so we would need to remove the note from http://symfony.com/doc/current/cookbook/bundles/extension.html and make Extension authors aware of this.

Or is this a "use at your own risk extension point" ?

@fabpot
Copy link
Member Author

@fabpot fabpot commented on f7aea2a May 17, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a supported extension point as it greatly simplifies the redefinition of existing services like the router.

@lsmith77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think as a result making all parameters extension points will lead to quite a BC nightmare. At the very least I guess it should be highlighted in the UPDATE.md and I guess the "note" in the above linked article needs to be removed.

Maybe a naming convention or documentation should be used to limit the parameters that are considered extension points?

Please sign in to comment.