This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

1089 lines
45 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
use Doctrine\Common\Annotations\Reader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Exception\LogicException;
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Validator\Validation;
/**
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>
2010-09-20 20:01:41 +01:00
* FrameworkExtension.
*
* @author Fabien Potencier <fabien@symfony.com>
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @author Jeremy Mikola <jmikola@gmail.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
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>
2010-09-20 20:01:41 +01:00
class FrameworkExtension extends Extension
{
private $formConfigEnabled = false;
private $translationConfigEnabled = false;
private $sessionConfigEnabled = false;
/**
* @var string|null
*/
private $kernelRootHash;
/**
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* Responds to the app.config configuration parameter.
*
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param array $configs
* @param ContainerBuilder $container
*
* @throws LogicException
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$loader->load('web.xml');
$loader->load('services.xml');
$loader->load('fragment_renderer.xml');
2010-10-25 15:55:20 +01:00
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
// A translator must always be registered (as support is included by
// default in the Form component). If disabled, an identity translator
// will be used and everything will still work as expected.
$loader->load('translation.xml');
// Property access is used by both the Form and the Validator component
$loader->load('property_access.xml');
// Load Cache configuration first as it is used by other components
$loader->load('cache_pools.xml');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
2012-09-29 19:56:08 +01:00
if (isset($config['secret'])) {
$container->setParameter('kernel.secret', $config['secret']);
}
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
2013-08-06 08:14:49 +01:00
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
$container->setParameter('kernel.default_locale', $config['default_locale']);
if (!empty($config['test'])) {
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$loader->load('test.xml');
}
if ($this->isConfigEnabled($container, $config['session'])) {
$this->sessionConfigEnabled = true;
$this->registerSessionConfiguration($config['session'], $container, $loader);
}
if ($this->isConfigEnabled($container, $config['request'])) {
$this->registerRequestConfiguration($config['request'], $container, $loader);
}
if ($this->isConfigEnabled($container, $config['form'])) {
$this->formConfigEnabled = true;
$this->registerFormConfiguration($config, $container, $loader);
$config['validation']['enabled'] = true;
if (!class_exists('Symfony\Component\Validator\Validation')) {
throw new LogicException('The Validator component is required to use the Form component.');
}
}
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
if ($this->isConfigEnabled($container, $config['assets'])) {
2014-12-28 18:57:17 +00:00
$this->registerAssetsConfiguration($config['assets'], $container, $loader);
}
if ($this->isConfigEnabled($container, $config['templating'])) {
$this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader);
2013-01-22 09:24:26 +00:00
}
$this->registerValidationConfiguration($config['validation'], $container, $loader);
$this->registerEsiConfiguration($config['esi'], $container, $loader);
2014-03-23 00:04:57 +00:00
$this->registerSsiConfiguration($config['ssi'], $container, $loader);
$this->registerFragmentsConfiguration($config['fragments'], $container, $loader);
$this->registerTranslatorConfiguration($config['translator'], $container);
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
$this->registerCacheConfiguration($config['cache'], $container, $loader);
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
if ($this->isConfigEnabled($container, $config['router'])) {
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
$this->registerRouterConfiguration($config['router'], $container, $loader);
}
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
$this->registerPropertyAccessConfiguration($config['property_access'], $container);
if (isset($config['serializer'])) {
$this->registerSerializerConfiguration($config['serializer'], $container, $loader);
2013-01-20 18:39:49 +00:00
}
2015-09-28 12:22:50 +01:00
if (isset($config['property_info'])) {
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
}
$loader->load('debug_prod.xml');
$definition = $container->findDefinition('debug.debug_handlers_listener');
if ($container->hasParameter('templating.helper.code.file_link_format')) {
2014-09-30 08:39:40 +01:00
$definition->replaceArgument(5, '%templating.helper.code.file_link_format%');
}
if ($container->getParameter('kernel.debug')) {
$definition->replaceArgument(2, E_ALL & ~(E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR | E_RECOVERABLE_ERROR));
$loader->load('debug.xml');
// replace the regular event_dispatcher service with the debug one
$definition = $container->findDefinition('event_dispatcher');
$definition->setPublic(false);
$container->setDefinition('debug.event_dispatcher.parent', $definition);
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
} else {
$definition->replaceArgument(1, null);
}
$this->addClassesToCompile(array(
'Symfony\\Component\\Config\\FileLocator',
'Symfony\\Component\\Debug\\ErrorHandler',
'Symfony\\Component\\EventDispatcher\\Event',
'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher',
'Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener',
'Symfony\\Component\\HttpKernel\\EventListener\\RouterListener',
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver',
'Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver',
'Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata',
'Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadataFactory',
'Symfony\\Component\\HttpKernel\\Event\\KernelEvent',
'Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent',
'Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent',
'Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent',
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent',
'Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent',
'Symfony\\Component\\HttpKernel\\KernelEvents',
'Symfony\\Component\\HttpKernel\\Config\\FileLocator',
refactored bundle management Before I explain the changes, let's talk about the current state. Before this patch, the registerBundleDirs() method returned an ordered (for resource overloading) list of namespace prefixes and the path to their location. Here are some problems with this approach: * The paths set by this method and the paths configured for the autoloader can be disconnected (leading to unexpected behaviors); * A bundle outside these paths worked, but unexpected behavior can occur; * Choosing a bundle namespace was limited to the registered namespace prefixes, and their number should stay low enough (for performance reasons) -- moreover the current Bundle\ and Application\ top namespaces does not respect the standard rules for namespaces (first segment should be the vendor name); * Developers must understand the concept of "namespace prefixes" to understand the overloading mechanism, which is one more thing to learn, which is Symfony specific; * Each time you want to get a resource that can be overloaded (a template for instance), Symfony would have tried all namespace prefixes one after the other until if finds a matching file. But that can be computed in advance to reduce the overhead. Another topic which was not really well addressed is how you can reference a file/resource from a bundle (and take into account the possibility of overloading). For instance, in the routing, you can import a file from a bundle like this: <import resource="FrameworkBundle/Resources/config/internal.xml" /> Again, this works only because we have a limited number of possible namespace prefixes. This patch addresses these problems and some more. First, the registerBundleDirs() method has been removed. It means that you are now free to use any namespace for your bundles. No need to have specific prefixes anymore. You are also free to store them anywhere, in as many directories as you want. You just need to be sure that they are autoloaded correctly. The bundle "name" is now always the short name of the bundle class (like FrameworkBundle or SensioCasBundle). As the best practice is to prefix the bundle name with the vendor name, it's up to the vendor to ensure that each bundle name is unique. I insist that a bundle name must be unique. This was the opposite before as two bundles with the same name was how Symfony2 found inheritance. A new getParent() method has been added to BundleInterface. It returns the bundle name that the bundle overrides (this is optional of course). That way, there is no ordering problem anymore as the inheritance tree is explicitely defined by the bundle themselves. So, with this system, we can easily have an inheritance tree like the following: FooBundle < MyFooBundle < MyCustomFooBundle MyCustomFooBundle returns MyFooBundle for the getParent() method, and MyFooBundle returns FooBundle. If two bundles override the same bundle, an exception is thrown. Based on the bundle name, you can now reference any resource with this notation: @FooBundle/Resources/config/routing.xml @FooBundle/Controller/FooController.php This notation is the input of the Kernel::locateResource() method, which returns the location of the file (and of course it takes into account overloading). So, in the routing, you can now use the following: <import resource="@FrameworkBundle/Resources/config/internal.xml" /> The template loading mechanism also use this method under the hood. As a bonus, all the code that converts from internal notations to file names (controller names: ControllerNameParser, template names: TemplateNameParser, resource paths, ...) is now contained in several well-defined classes. The same goes for the code that look for templates (TemplateLocator), routing files (FileLocator), ... As a side note, it is really easy to also support multiple-inheritance for a bundle (for instance if a bundle returns an array of bundle names it extends). However, this is not implemented in this patch as I'm not sure we want to support that. How to upgrade: * Each bundle must now implement two new mandatory methods: getPath() and getNamespace(), and optionally the getParent() method if the bundle extends another one. Here is a common implementation for these methods: /** * {@inheritdoc} */ public function getParent() { return 'MyFrameworkBundle'; } /** * {@inheritdoc} */ public function getNamespace() { return __NAMESPACE__; } /** * {@inheritdoc} */ public function getPath() { return strtr(__DIR__, '\\', '/'); } * The registerBundleDirs() can be removed from your Kernel class; * If your code relies on getBundleDirs() or the kernel.bundle_dirs parameter, it should be upgraded to use the new interface (see Doctrine commands for many example of such a change); * When referencing a bundle, you must now always use its name (no more \ or / in bundle names) -- this transition was already done for most things before, and now applies to the routing as well; * Imports in routing files must be changed: Before: <import resource="Sensio/CasBundle/Resources/config/internal.xml" /> After: <import resource="@SensioCasBundle/Resources/config/internal.xml" />
2011-01-18 09:23:49 +00:00
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerNameParser',
2010-08-18 12:43:32 +01:00
'Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerResolver',
// Cannot be included because annotations will parse the big compiled class file
// 'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
2010-08-18 12:43:32 +01:00
));
}
2014-05-10 23:14:12 +01:00
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
/**
* Loads Form configuration.
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
*
* @param array $config A configuration array
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*
* @throws \LogicException
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
*/
private function registerFormConfiguration($config, ContainerBuilder $container, XmlFileLoader $loader)
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
{
$loader->load('form.xml');
if (null === $config['form']['csrf_protection']['enabled']) {
$config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
}
if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
$loader->load('form_csrf.xml');
$container->setParameter('form.type_extension.csrf.enabled', true);
$container->setParameter('form.type_extension.csrf.field_name', $config['form']['csrf_protection']['field_name']);
} else {
$container->setParameter('form.type_extension.csrf.enabled', false);
}
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
}
/**
* Loads the ESI configuration.
*
* @param array $config An ESI configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerEsiConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
$loader->load('esi.xml');
}
2014-03-23 00:04:57 +00:00
/**
* Loads the SSI configuration.
*
* @param array $config An SSI configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerSsiConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
$loader->load('ssi.xml');
}
2013-01-22 09:24:26 +00:00
/**
* Loads the fragments configuration.
2013-01-22 09:24:26 +00:00
*
* @param array $config A fragments configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
2013-01-22 09:24:26 +00:00
*/
private function registerFragmentsConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
2013-01-22 09:24:26 +00:00
{
if (!$this->isConfigEnabled($container, $config)) {
return;
2013-01-22 09:24:26 +00:00
}
$loader->load('fragment_listener.xml');
$container->setParameter('fragment.path', $config['path']);
2013-01-22 09:24:26 +00:00
}
/**
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* Loads the profiler configuration.
*
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param array $config A profiler configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param XmlFileLoader $loader An XmlFileLoader instance
*
* @throws \LogicException
*/
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
// this is needed for the WebProfiler to work even if the profiler is disabled
$container->setParameter('data_collector.templates', array());
return;
}
2015-02-06 10:24:56 +00:00
$loader->load('profiling.xml');
$loader->load('collectors.xml');
if ($this->formConfigEnabled) {
$loader->load('form_debug.xml');
}
2013-10-30 08:33:58 +00:00
if ($this->translationConfigEnabled) {
$loader->load('translation_debug.xml');
$container->getDefinition('translator.data_collector')->setDecoratedService('translator');
}
$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
2015-02-18 07:05:44 +00:00
list($class) = explode(':', $config['dsn'], 2);
if ('file' !== $class) {
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
}
$container->setParameter('profiler.storage.dsn', $config['dsn']);
if ($this->isConfigEnabled($container, $config['matcher'])) {
if (isset($config['matcher']['service'])) {
$container->setAlias('profiler.request_matcher', $config['matcher']['service']);
2013-06-24 21:26:23 +01:00
} elseif (isset($config['matcher']['ip']) || isset($config['matcher']['path']) || isset($config['matcher']['ips'])) {
$definition = $container->register('profiler.request_matcher', 'Symfony\\Component\\HttpFoundation\\RequestMatcher');
$definition->setPublic(false);
if (isset($config['matcher']['ip'])) {
$definition->addMethodCall('matchIp', array($config['matcher']['ip']));
}
2013-06-24 21:26:23 +01:00
if (isset($config['matcher']['ips'])) {
$definition->addMethodCall('matchIps', array($config['matcher']['ips']));
}
if (isset($config['matcher']['path'])) {
$definition->addMethodCall('matchPath', array($config['matcher']['path']));
}
}
}
if (!$config['collect']) {
$container->getDefinition('profiler')->addMethodCall('disable', array());
}
}
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
/**
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* Loads the router configuration.
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
*
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param array $config A router configuration array
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
* @param ContainerBuilder $container A ContainerBuilder instance
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param XmlFileLoader $loader An XmlFileLoader instance
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
*/
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerRouterConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
{
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$loader->load('routing.xml');
$container->setParameter('router.resource', $config['resource']);
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment')));
2011-07-18 09:05:28 +01:00
$router = $container->findDefinition('router.default');
$argument = $router->getArgument(2);
$argument['strict_requirements'] = $config['strict_requirements'];
if (isset($config['type'])) {
$argument['resource_type'] = $config['type'];
}
$router->replaceArgument(2, $argument);
$container->setParameter('request_listener.http_port', $config['http_port']);
$container->setParameter('request_listener.https_port', $config['https_port']);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$this->addClassesToCompile(array(
'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
'Symfony\\Component\\Routing\\RequestContext',
'Symfony\\Component\\Routing\\Router',
'Symfony\\Bundle\\FrameworkBundle\\Routing\\RedirectableUrlMatcher',
2011-07-18 09:05:28 +01:00
$container->findDefinition('router.default')->getClass(),
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
));
}
/**
* Loads the session configuration.
*
* @param array $config A session configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerSessionConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
{
$loader->load('session.xml');
// session storage
$container->setAlias('session.storage', $config['storage_id']);
$options = array();
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
if (isset($config[$key])) {
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
$options[$key] = $config[$key];
}
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
}
$container->setParameter('session.storage.options', $options);
2010-11-25 08:04:24 +00:00
// session handler (the internal callback registered with PHP session management)
2013-11-17 14:05:15 +00:00
if (null === $config['handler_id']) {
// Set the handler class to be null
$container->getDefinition('session.storage.native')->replaceArgument(1, null);
$container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null);
} else {
$handlerId = $config['handler_id'];
if ($config['metadata_update_threshold'] > 0) {
$container->getDefinition('session.handler.write_check')->addArgument(new Reference($handlerId));
$handlerId = 'session.handler.write_check';
}
$container->setAlias('session.handler', $handlerId);
}
$container->setParameter('session.save_path', $config['save_path']);
$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\PhpBridgeSessionStorage',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\AbstractProxy',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\SessionHandlerProxy',
$container->getDefinition('session')->getClass(),
2010-11-25 08:04:24 +00:00
));
if ($container->hasDefinition($config['storage_id'])) {
$this->addClassesToCompile(array(
$container->findDefinition('session.storage')->getClass(),
));
}
$container->setParameter('session.metadata.update_threshold', $config['metadata_update_threshold']);
removed Symfony\Framework Things have been moved to Symfony\Component\HttpKernel and Symfony\Bundle\FrameworkBundle The kernel configuration namespace was removed and merged with the main web configuration namespace (kernel:config => web:config, kernel:test => web:test, and kernel:session => web:session): Before: <kernel:config charset="UTF-8" error_handler="null" /> <web:config csrf-secret="xxxxxxxxxx"> <web:router resource="%kernel.root_dir%/config/routing.xml" /> <web:validation enabled="true" annotations="true" /> </web:config> After: <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> Renamed classes: Symfony\{Framework => Bundle\FrameworkBundle}\Cache\Cache Symfony\{Framework => Bundle\FrameworkBundle}\Client Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcher Symfony\{Framework => Bundle\FrameworkBundle}\Debug\EventDispatcherTraceableInterface Symfony\{Framework => Bundle\FrameworkBundle}\EventDispatcher Symfony\{Framework => Component\HttpFoundation}\UniversalClassLoader Symfony\{Framework => Component\HttpKernel}\Bundle\Bundle Symfony\{Framework => Component\HttpKernel}\Bundle\BundleInterface Symfony\{Framework => Component\HttpKernel}\ClassCollectionLoader Symfony\{Framework => Component\HttpKernel}\Debug\ErrorException Symfony\{Framework => Component\HttpKernel}\Debug\ErrorHandler Symfony\{Bundle\FrameworkBundle => Component\HttpKernel}\Debug\ExceptionListener Symfony\{Framework => Component\HttpKernel}\Kernel
2010-09-15 19:49:16 +01:00
}
/**
* Loads the request configuration.
*
2015-06-21 19:10:28 +01:00
* @param array $config A request configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerRequestConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if ($config['formats']) {
$loader->load('request.xml');
$container
->getDefinition('request.add_request_formats_listener')
->replaceArgument(0, $config['formats'])
;
}
}
/**
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* Loads the templating configuration.
*
2012-05-18 18:41:48 +01:00
* @param array $config A templating configuration array
2011-04-23 16:05:44 +01:00
* @param string $ide
* @param ContainerBuilder $container A ContainerBuilder instance
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerTemplatingConfiguration(array $config, $ide, ContainerBuilder $container, XmlFileLoader $loader)
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>
2010-09-20 20:01:41 +01:00
{
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$loader->load('templating.xml');
if (!$container->hasParameter('templating.helper.code.file_link_format')) {
$links = array(
'textmate' => 'txmt://open?url=file://%%f&line=%%l',
'macvim' => 'mvim://open?url=file://%%f&line=%%l',
'emacs' => 'emacs://open?url=file://%%f&line=%%l',
'sublime' => 'subl://open?url=file://%%f&line=%%l',
);
$container->setParameter('templating.helper.code.file_link_format', str_replace('%', '%%', ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) ?: (isset($links[$ide]) ? $links[$ide] : $ide));
}
$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);
if ($container->getParameter('kernel.debug')) {
$logger = new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE);
$container->getDefinition('templating.loader.cache')
->addTag('monolog.logger', array('channel' => 'templating'))
->addMethodCall('setLogger', array($logger));
$container->getDefinition('templating.loader.chain')
->addTag('monolog.logger', array('channel' => 'templating'))
->addMethodCall('setLogger', array($logger));
}
if (!empty($config['loaders'])) {
2013-12-28 07:46:05 +00:00
$loaders = array_map(function ($loader) { return new Reference($loader); }, $config['loaders']);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
// Use a delegation unless only a single loader was registered
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
if (1 === count($loaders)) {
$container->setAlias('templating.loader', (string) reset($loaders));
} else {
$container->getDefinition('templating.loader.chain')->addArgument($loaders);
$container->setAlias('templating.loader', 'templating.loader.chain');
}
}
$container->setParameter('templating.loader.cache.path', null);
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
if (isset($config['cache'])) {
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
// 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');
$container->setParameter('templating.loader.cache.path', $config['cache']);
$container->setDefinition('templating.loader', $loaderCache);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables',
2011-02-10 17:20:44 +00:00
'Symfony\\Bundle\\FrameworkBundle\\Templating\\TemplateReference',
'Symfony\\Bundle\\FrameworkBundle\\Templating\\TemplateNameParser',
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container->findDefinition('templating.locator')->getClass(),
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>
2010-09-20 20:01:41 +01:00
));
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container->setParameter('templating.engines', $config['engines']);
2013-12-28 07:46:05 +00:00
$engines = array_map(function ($engine) { return new Reference('templating.engine.'.$engine); }, $config['engines']);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
2011-02-26 17:41:17 +00:00
// Use a delegation unless only a single engine was registered
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
if (1 === count($engines)) {
$container->setAlias('templating', (string) reset($engines));
} else {
foreach ($engines as $engine) {
$container->getDefinition('templating.engine.delegating')->addMethodCall('addEngine', array($engine));
}
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$container->setAlias('templating', 'templating.engine.delegating');
}
$container->getDefinition('fragment.renderer.hinclude')
->addTag('kernel.fragment_renderer', array('alias' => 'hinclude'))
->replaceArgument(0, new Reference('templating'))
;
// configure the PHP engine if needed
if (in_array('php', $config['engines'], true)) {
$loader->load('templating_php.xml');
$container->setParameter('templating.helper.form.resources', $config['form']['resources']);
if ($container->getParameter('kernel.debug')) {
$loader->load('templating_debug.xml');
$container->setDefinition('templating.engine.php', $container->findDefinition('debug.templating.engine.php'));
$container->setAlias('debug.templating.engine.php', 'templating.engine.php');
}
$this->addClassesToCompile(array(
'Symfony\\Component\\Templating\\Storage\\FileStorage',
'Symfony\\Bundle\\FrameworkBundle\\Templating\\PhpEngine',
'Symfony\\Bundle\\FrameworkBundle\\Templating\\Loader\\FilesystemLoader',
));
if ($container->has('assets.packages')) {
$container->getDefinition('templating.helper.assets')->replaceArgument(0, new Reference('assets.packages'));
} else {
$container->removeDefinition('templating.helper.assets');
}
}
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>
2010-09-20 20:01:41 +01:00
}
2014-12-28 18:57:17 +00:00
/**
* Loads the assets configuration.
*
* @param array $config A assets configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerAssetsConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
2015-02-12 12:06:55 +00:00
$loader->load('assets.xml');
2016-01-25 21:22:29 +00:00
$defaultVersion = null;
if ($config['version_strategy']) {
$defaultVersion = new Reference($config['version_strategy']);
} else {
$defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], '_default');
}
2014-12-28 18:57:17 +00:00
$defaultPackage = $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
$container->setDefinition('assets._default_package', $defaultPackage);
$namedPackages = array();
foreach ($config['packages'] as $name => $package) {
2016-01-25 21:22:29 +00:00
if (null !== $package['version_strategy']) {
$version = new Reference($package['version_strategy']);
Merge branch '3.0' * 3.0: (105 commits) [Console] remove readline support bumped Symfony version to 3.0.3 updated VERSION for 3.0.2 updated CHANGELOG for 3.0.2 [Routing] added a suggestion to add the HttpFoundation component. [FrameworkBundle] fix assets and templating tests [ClassLoader] fix ApcClassLoader tests on HHVM [travis] Add some comments changed operator from and to && [DependencyInjection] Remove unused parameter [Process] Fix transient tests for incremental outputs [Console] Add missing `@require` annotation in test Fix merge [appveyor] Fix failure reporting [#17634] move DebugBundle license file Limit Ldap component version for the 3.0 branch backport GlobTest from 2.7 branch Move licenses according to new best practices [FrameworkBundle] Remove unused code in test [2.3] Fixed an undefined variable in Glob::toRegex ... Conflicts: .travis.yml composer.json src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_item.html.twig src/Symfony/Component/Console/CHANGELOG.md src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/PropertyInfo/Tests/PropertyInfoExtractorTest.php src/Symfony/Component/Yaml/Tests/ParserTest.php
2016-02-04 12:57:09 +00:00
} elseif (!array_key_exists('version', $package)) {
2014-12-28 18:57:17 +00:00
$version = $defaultVersion;
} else {
$format = $package['version_format'] ?: $config['version_format'];
$version = $this->createVersion($container, $package['version'], $format, $name);
}
$container->setDefinition('assets._package_'.$name, $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version));
$namedPackages[$name] = new Reference('assets._package_'.$name);
}
$container->getDefinition('assets.packages')
->replaceArgument(0, new Reference('assets._default_package'))
->replaceArgument(1, $namedPackages)
;
}
/**
* Returns a definition for an asset package.
*/
private function createPackageDefinition($basePath, array $baseUrls, Reference $version)
{
if ($basePath && $baseUrls) {
throw new \LogicException('An asset package cannot have base URLs and base paths.');
}
if (!$baseUrls) {
$package = new DefinitionDecorator('assets.path_package');
return $package
->setPublic(false)
->replaceArgument(0, $basePath)
->replaceArgument(1, $version)
;
}
$package = new DefinitionDecorator('assets.url_package');
return $package
->setPublic(false)
->replaceArgument(0, $baseUrls)
->replaceArgument(1, $version)
;
}
private function createVersion(ContainerBuilder $container, $version, $format, $name)
2014-12-28 18:57:17 +00:00
{
if (null === $version) {
2014-12-28 18:57:17 +00:00
return new Reference('assets.empty_version_strategy');
}
$def = new DefinitionDecorator('assets.static_version_strategy');
$def
->replaceArgument(0, $version)
->replaceArgument(1, $format)
;
$container->setDefinition('assets._version_'.$name, $def);
return new Reference('assets._version_'.$name);
}
/**
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* Loads the translator configuration.
*
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param array $config A translator configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
*/
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
$this->translationConfigEnabled = true;
// Use the "real" translator instead of the identity default
$container->setAlias('translator', 'translator.default');
$translator = $container->findDefinition('translator.default');
$translator->addMethodCall('setFallbackLocales', array($config['fallbacks']));
2014-05-10 23:14:12 +01:00
$container->setParameter('translator.logging', $config['logging']);
// Discover translation directories
$dirs = array();
if (class_exists('Symfony\Component\Validator\Validation')) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
$dirs[] = dirname($r->getFileName()).'/Resources/translations';
}
if (class_exists('Symfony\Component\Form\Form')) {
$r = new \ReflectionClass('Symfony\Component\Form\Form');
$dirs[] = dirname($r->getFileName()).'/Resources/translations';
}
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
}
$rootDir = $container->getParameter('kernel.root_dir');
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
$reflection = new \ReflectionClass($class);
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
$dirs[] = $dir;
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
$dirs[] = $dir;
}
}
foreach ($config['paths'] as $dir) {
if (is_dir($dir)) {
$dirs[] = $dir;
} else {
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
}
}
if (is_dir($dir = $rootDir.'/Resources/translations')) {
$dirs[] = $dir;
}
// Register translation resources
if ($dirs) {
foreach ($dirs as $dir) {
$container->addResource(new DirectoryResource($dir));
}
$files = array();
$finder = Finder::create()
->files()
->filter(function (\SplFileInfo $file) {
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
})
->in($dirs)
;
foreach ($finder as $file) {
2016-03-24 11:33:34 +00:00
list(, $locale) = explode('.', $file->getBasename(), 3);
if (!isset($files[$locale])) {
$files[$locale] = array();
}
$files[$locale][] = (string) $file;
}
$options = array_merge(
$translator->getArgument(3),
array('resource_files' => $files)
);
$translator->replaceArgument(3, $options);
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
}
}
/**
* Loads the validator configuration.
*
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param array $config A validation configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
2011-01-24 19:50:31 +00:00
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
private function registerValidationConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
[FrameworkBundle] Integrate Configuration\Builder class for config merging and normalization This fixes some BC problems introduced in f9138d313b83f951cf82a2f7f902a2d6dd14fbb3. Some top-level can now be simply enabled by providing true/null in PHP/YAML. Additionally, the Configuration\Builder allows options to be unset by providing "false" (helpful for overriding activation in a previous config file). All options supporting these behaviors can be found in the Configuration.php file (look for canBeUnset() and treatNull/TrueLike()). Major changes: * Removed "enabled" option for profiler config. Profiler is now enabled if its config is true, null or a map. * Restore original config structure for validation namespaces. In PHP/YAML, namespaces are defined under annotations as an alternative to false (disabled) and true/null (enabled). For XML, annotation remains a boolean attribute for validation and a one or more optional namespace tags may appear within <app:validation />. During config normalization, namespace tags under validation will be moved to annotations to conform to the PHP/YAML structure (this occurs transparently to the user). * Restore behavior for router/templating config sections being optional (as shown in changes to session/validation test fixtures). If either top-level section is unset in the configuration, neither feature will be enabled and the user will no longer receive exceptions due to missing a resource option (router) or engines (templating). Resource/engines will still be properly required if the respective feature is enabled. * Remove unused router type option from XML config XSD. Type is only relevant for import statements, so this option is likely useless. Additional small changes: * Added isset()'s, since config options may be unset * Wrap registerXxxConfiguration() calls in isset() checks * Load translation.xml in configLoad(), since it's always required * Default cache_warmer value (!kernel.debug) is determined via Configuration class Things to be fixed: * Configuration\Builder doesn't seem to respect isRequired() and requiresAtLeastOneElement() (or I haven't set it properly); this should replace the need for FrameworkExtension to throw exceptions for bad router/templating configs * The config nodes for session options don't have the "pdo." prefix, as dots are not allowed in node names. To preserve BC for now, the "pdo." prefix is still allowed (and mandated by XSD) in configuration files. In the future, we may just want to do away with the "pdo." prefix. * Translator has an "enabled" option. If there's no use case for setting "fallback" independently (when "enabled" is false), perhaps "enabled" should be removed entirely and translator should function like profiler currently does. * Profiler matcher merging might need to be adjusted so multiple configs simply overwrite matcher instead of merging its array keys.
2011-02-06 09:29:16 +00:00
$loader->load('validator.xml');
$validatorBuilder = $container->getDefinition('validator.builder');
$container->setParameter('validator.translation_domain', $config['translation_domain']);
list($xmlMappings, $yamlMappings) = $this->getValidatorMappingFiles($container);
if (count($xmlMappings) > 0) {
$validatorBuilder->addMethodCall('addXmlMappings', array($xmlMappings));
}
if (count($yamlMappings) > 0) {
$validatorBuilder->addMethodCall('addYamlMappings', array($yamlMappings));
}
$definition = $container->findDefinition('validator.email');
$definition->replaceArgument(0, $config['strict_email']);
if (array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
$validatorBuilder->addMethodCall('enableAnnotationMapping', array(new Reference('annotation_reader')));
}
if (array_key_exists('static_method', $config) && $config['static_method']) {
foreach ($config['static_method'] as $methodName) {
$validatorBuilder->addMethodCall('addMethodMapping', array($methodName));
}
}
if (!$container->getParameter('kernel.debug')) {
$container->setParameter(
'validator.mapping.cache.prefix',
'validator_'.$this->getKernelRootHash($container)
);
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference($config['cache'])));
}
}
private function getValidatorMappingFiles(ContainerBuilder $container)
{
$files = array(array(), array());
if (interface_exists('Symfony\Component\Form\FormInterface')) {
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
$files[0][] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
$container->addResource(new FileResource($files[0][0]));
}
$bundles = $container->getParameter('kernel.bundles');
foreach ($bundles as $bundle) {
$reflection = new \ReflectionClass($bundle);
$dirname = dirname($reflection->getFileName());
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
$files[0][] = realpath($file);
$container->addResource(new FileResource($file));
}
if (is_file($file = $dirname.'/Resources/config/validation.yml')) {
$files[1][] = realpath($file);
$container->addResource(new FileResource($file));
}
if (is_dir($dir = $dirname.'/Resources/config/validation')) {
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
$files[0][] = $file->getRealpath();
}
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
$files[1][] = $file->getRealpath();
}
$container->addResource(new DirectoryResource($dir));
}
}
return $files;
}
private function registerAnnotationsConfiguration(array $config, ContainerBuilder $container, $loader)
{
$loader->load('annotations.xml');
if ('none' !== $config['cache']) {
if ('file' === $config['cache']) {
$cacheDir = $container->getParameterBag()->resolveValue($config['file_cache_dir']);
if (!is_dir($cacheDir) && false === @mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
}
$container
->getDefinition('annotations.filesystem_cache')
->replaceArgument(0, $cacheDir)
;
}
$container
->getDefinition('annotations.cached_reader')
->replaceArgument(1, new Reference('file' !== $config['cache'] ? $config['cache'] : 'annotations.filesystem_cache'))
2011-05-24 12:29:44 +01:00
->replaceArgument(2, $config['debug'])
->addAutowiringType(Reader::class)
;
2011-05-24 12:29:44 +01:00
$container->setAlias('annotation_reader', 'annotations.cached_reader');
}
}
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container)
{
$container
->getDefinition('property_accessor')
->replaceArgument(0, $config['magic_call'])
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
;
}
/**
* Loads the security configuration.
*
* @param array $config A CSRF configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*
* @throws \LogicException
*/
private function registerSecurityCsrfConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
if (!$this->sessionConfigEnabled) {
throw new \LogicException('CSRF protection needs sessions to be enabled.');
}
// Enable services for CSRF protection (even without forms)
$loader->load('security_csrf.xml');
}
/**
* Loads the serializer configuration.
*
* @param array $config A serializer configuration array
* @param ContainerBuilder $container A ContainerBuilder instance
* @param XmlFileLoader $loader An XmlFileLoader instance
*/
private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}
if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
// Run after serializer.normalizer.object
$definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
$definition->setPublic(false);
$definition->addTag('serializer.normalizer', ['priority' => -920]);
}
if (class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) {
// Run before serializer.normalizer.object
$definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class);
$definition->setPublic(false);
$definition->addTag('serializer.normalizer', array('priority' => -910));
}
if (class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) {
// Run before serializer.normalizer.object
$definition = $container->register('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class);
$definition->setPublic(false);
$definition->addTag('serializer.normalizer', array('priority' => -900));
}
$loader->load('serializer.xml');
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
$serializerLoaders = array();
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
$annotationLoader = new Definition(
'Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader',
array(new Reference('annotation_reader'))
);
$annotationLoader->setPublic(false);
$serializerLoaders[] = $annotationLoader;
}
$bundles = $container->getParameter('kernel.bundles');
foreach ($bundles as $bundle) {
$reflection = new \ReflectionClass($bundle);
2015-07-09 17:32:09 +01:00
$dirname = dirname($reflection->getFileName());
if (is_file($file = $dirname.'/Resources/config/serialization.xml')) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array(realpath($file)));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
$container->addResource(new FileResource($file));
}
if (is_file($file = $dirname.'/Resources/config/serialization.yml')) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array(realpath($file)));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
$container->addResource(new FileResource($file));
}
if (is_dir($dir = $dirname.'/Resources/config/serialization')) {
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file->getRealpath()));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
}
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array($file->getRealpath()));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
}
$container->addResource(new DirectoryResource($dir));
}
}
$chainLoader->replaceArgument(0, $serializerLoaders);
if (isset($config['cache']) && $config['cache']) {
@trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. You can configure a cache pool called "serializer" under "framework.cache.pools" instead.', E_USER_DEPRECATED);
$container->setParameter(
'serializer.mapping.cache.prefix',
'serializer_'.$this->getKernelRootHash($container)
);
$container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument(
1, new Reference($config['cache'])
);
} elseif (!$container->getParameter('kernel.debug')) {
$cacheMetadataFactory = new Definition(
CacheClassMetadataFactory::class,
array(
new Reference('serializer.mapping.class_metadata_factory.inner'),
new Reference('cache.pool.serializer'),
)
);
$cacheMetadataFactory->setPublic(false);
$cacheMetadataFactory->setDecoratedService('serializer.mapping.class_metadata_factory');
$container->setDefinition('serializer.mapping.cache_class_metadata_factory', $cacheMetadataFactory);
}
if (isset($config['name_converter']) && $config['name_converter']) {
$container->getDefinition('serializer.normalizer.object')->replaceArgument(1, new Reference($config['name_converter']));
}
}
2015-09-28 12:22:50 +01:00
/**
* Loads property info configuration.
*
* @param array $config
* @param ContainerBuilder $container
* @param XmlFileLoader $loader
*/
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
if (!$this->isConfigEnabled($container, $config)) {
2015-09-28 12:22:50 +01:00
return;
}
$loader->load('property_info.xml');
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
2015-09-28 12:22:50 +01:00
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
$definition->addTag('property_info.description_extractor', array('priority' => -1000));
$definition->addTag('property_info.type_extractor', array('priority' => -1001));
}
}
private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
{
foreach ($config['pools'] as $name => $poolConfig) {
$poolDefinition = new DefinitionDecorator($poolConfig['adapter']);
$poolDefinition->setPublic($poolConfig['public']);
unset($poolConfig['adapter'], $poolConfig['public']);
$poolDefinition->addTag('cache.pool', $poolConfig);
$container->setDefinition('cache.pool.'.$name, $poolDefinition);
}
$this->addClassesToCompile(array(
'Psr\Cache\CacheItemInterface',
'Psr\Cache\CacheItemPoolInterface',
'Symfony\Component\Cache\Adapter\AdapterInterface',
'Symfony\Component\Cache\Adapter\AbstractAdapter',
'Symfony\Component\Cache\CacheItem',
));
}
/**
* Gets a hash of the kernel root directory.
*
* @param ContainerBuilder $container
*
* @return string
*/
private function getKernelRootHash(ContainerBuilder $container)
{
if (!$this->kernelRootHash) {
$this->kernelRootHash = hash('sha256', $container->getParameter('kernel.root_dir'));
}
return $this->kernelRootHash;
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
2010-06-27 17:54:03 +01:00
return __DIR__.'/../Resources/config/schema';
}
public function getNamespace()
{
return 'http://symfony.com/schema/dic/symfony';
}
}