2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2011-05-03 13:36:42 +01:00
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-05-21 00:08:03 +01:00
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
2011-01-24 19:50:31 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
2011-02-10 15:15:51 +00:00
|
|
|
use Symfony\Component\Config\Resource\FileResource;
|
2012-04-20 14:14:14 +01:00
|
|
|
use Symfony\Component\Config\Resource\DirectoryResource;
|
2010-09-27 08:46:15 +01:00
|
|
|
use Symfony\Component\Finder\Finder;
|
2011-01-16 09:17:38 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
2011-02-10 15:15:51 +00:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-20 20:01:41 +01:00
|
|
|
* FrameworkExtension.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-01-24 19:50:31 +00:00
|
|
|
* @author Jeremy Mikola <jmikola@gmail.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
2010-09-20 20:01:41 +01:00
|
|
|
class FrameworkExtension extends Extension
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-06-07 08:08:35 +01:00
|
|
|
/**
|
2011-01-24 19:50:31 +00:00
|
|
|
* Responds to the app.config configuration parameter.
|
2010-06-07 08:08:35 +01:00
|
|
|
*
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param array $configs
|
|
|
|
* @param ContainerBuilder $container
|
2010-06-07 08:08:35 +01:00
|
|
|
*/
|
2011-02-15 04:58:18 +00:00
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
2010-02-24 14:42:04 +00:00
|
|
|
{
|
2011-02-09 23:44:02 +00:00
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
2010-07-17 16:40:38 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
$loader->load('web.xml');
|
|
|
|
$loader->load('services.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');
|
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
if ($container->getParameter('kernel.debug')) {
|
|
|
|
$loader->load('debug.xml');
|
2011-03-13 18:16:56 +00:00
|
|
|
$container->setDefinition('event_dispatcher', $container->findDefinition('debug.event_dispatcher'));
|
|
|
|
$container->setAlias('debug.event_dispatcher', 'event_dispatcher');
|
2011-10-17 09:27:10 +01:00
|
|
|
|
|
|
|
$container->setDefinition('controller_resolver', $container->findDefinition('debug.controller_resolver'));
|
|
|
|
$container->setAlias('debug.controller_resolver', 'controller_resolver');
|
2011-01-18 19:18:28 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 19:33:02 +01:00
|
|
|
$configuration = $this->getConfiguration($configs, $container);
|
2011-07-18 16:46:00 +01:00
|
|
|
$config = $this->processConfiguration($configuration, $configs);
|
2010-09-15 19:49:16 +01:00
|
|
|
|
|
|
|
if (isset($config['charset'])) {
|
|
|
|
$container->setParameter('kernel.charset', $config['charset']);
|
|
|
|
}
|
2011-04-28 09:49:59 +01:00
|
|
|
$container->setParameter('kernel.secret', $config['secret']);
|
2011-02-06 20:29:13 +00:00
|
|
|
|
2011-07-06 16:42:58 +01:00
|
|
|
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);
|
2011-07-05 18:38:29 +01:00
|
|
|
|
2011-10-05 10:09:51 +01:00
|
|
|
$container->setParameter('kernel.default_locale', $config['default_locale']);
|
|
|
|
|
2011-02-10 20:40:00 +00:00
|
|
|
if (!empty($config['test'])) {
|
2011-01-24 19:50:31 +00:00
|
|
|
$loader->load('test.xml');
|
2011-01-24 10:16:22 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 12:14:51 +01:00
|
|
|
if (isset($config['session'])) {
|
|
|
|
$this->registerSessionConfiguration($config['session'], $container, $loader);
|
|
|
|
}
|
|
|
|
|
2011-07-25 13:33:12 +01:00
|
|
|
if (isset($config['form']) && !empty($config['form']['enabled'])) {
|
2011-05-18 12:14:51 +01:00
|
|
|
$this->registerFormConfiguration($config, $container, $loader);
|
|
|
|
$config['validation']['enabled'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($config['validation']['enabled'])) {
|
|
|
|
$this->registerValidationConfiguration($config['validation'], $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 (isset($config['esi'])) {
|
|
|
|
$this->registerEsiConfiguration($config['esi'], $loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['profiler'])) {
|
|
|
|
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['router'])) {
|
|
|
|
$this->registerRouterConfiguration($config['router'], $container, $loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['templating'])) {
|
2011-04-05 07:03:29 +01:00
|
|
|
$this->registerTemplatingConfiguration($config['templating'], $config['ide'], $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 (isset($config['translator'])) {
|
|
|
|
$this->registerTranslatorConfiguration($config['translator'], $container);
|
|
|
|
}
|
|
|
|
|
2011-05-03 13:36:42 +01:00
|
|
|
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
|
|
|
|
|
2011-01-16 09:17:38 +00:00
|
|
|
$this->addClassesToCompile(array(
|
2010-08-20 22:09:55 +01:00
|
|
|
'Symfony\\Component\\HttpFoundation\\ParameterBag',
|
|
|
|
'Symfony\\Component\\HttpFoundation\\HeaderBag',
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Component\\HttpFoundation\\FileBag',
|
|
|
|
'Symfony\\Component\\HttpFoundation\\ServerBag',
|
2010-08-20 22:09:55 +01:00
|
|
|
'Symfony\\Component\\HttpFoundation\\Request',
|
|
|
|
'Symfony\\Component\\HttpFoundation\\Response',
|
2010-11-27 14:14:58 +00:00
|
|
|
'Symfony\\Component\\HttpFoundation\\ResponseHeaderBag',
|
2010-08-18 12:43:32 +01:00
|
|
|
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Component\\Config\\FileLocator',
|
|
|
|
|
2011-03-18 08:24:07 +00:00
|
|
|
'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface',
|
2011-03-18 11:07:42 +00:00
|
|
|
'Symfony\\Component\\EventDispatcher\\EventDispatcher',
|
2011-03-18 08:24:07 +00:00
|
|
|
'Symfony\\Component\\EventDispatcher\\Event',
|
|
|
|
'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface',
|
2012-04-02 16:48:37 +01:00
|
|
|
'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher',
|
2011-03-18 08:24:07 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\HttpKernel',
|
2011-05-31 09:09:25 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener',
|
2011-10-10 13:41:48 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\EventListener\\RouterListener',
|
2010-08-20 22:09:55 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolver',
|
2010-11-25 08:04:24 +00:00
|
|
|
'Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface',
|
2011-03-13 18:16:56 +00:00
|
|
|
'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',
|
2011-06-21 15:34:33 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\KernelEvents',
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Component\\HttpKernel\\Config\\FileLocator',
|
2010-08-10 20:44:04 +01:00
|
|
|
|
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',
|
2011-07-23 15:40:25 +01:00
|
|
|
// Cannot be included because annotations will parse the big compiled class file
|
|
|
|
// 'Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller',
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\HttpKernel',
|
2010-08-18 12:43:32 +01:00
|
|
|
));
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 19:33:02 +01:00
|
|
|
public function getConfiguration(array $config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
return new Configuration($container->getParameter('kernel.debug'));
|
|
|
|
}
|
|
|
|
|
2010-09-15 19:49:16 +01:00
|
|
|
/**
|
2011-05-18 11:54:16 +01:00
|
|
|
* Loads Form configuration.
|
2010-09-15 19:49:16 +01:00
|
|
|
*
|
2011-05-18 11:54:16 +01:00
|
|
|
* @param array $config A configuration array
|
2010-09-15 19:49:16 +01:00
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
2011-05-18 11:54:16 +01:00
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
2010-09-15 19:49:16 +01:00
|
|
|
*/
|
2011-05-18 11:54:16 +01:00
|
|
|
private function registerFormConfiguration($config, ContainerBuilder $container, XmlFileLoader $loader)
|
2010-09-15 19:49:16 +01:00
|
|
|
{
|
2011-05-18 11:54:16 +01:00
|
|
|
$loader->load('form.xml');
|
|
|
|
if (isset($config['csrf_protection'])) {
|
|
|
|
if (!isset($config['session'])) {
|
|
|
|
throw new \LogicException('CSRF protection needs that sessions are enabled.');
|
|
|
|
}
|
|
|
|
$loader->load('form_csrf.xml');
|
|
|
|
|
|
|
|
$container->setParameter('form.type_extension.csrf.enabled', $config['csrf_protection']['enabled']);
|
|
|
|
$container->setParameter('form.type_extension.csrf.field_name', $config['csrf_protection']['field_name']);
|
|
|
|
}
|
2010-09-15 19:49:16 +01:00
|
|
|
}
|
|
|
|
|
2011-01-17 15:21:46 +00:00
|
|
|
/**
|
|
|
|
* Loads the ESI configuration.
|
|
|
|
*
|
2011-04-23 16:05:44 +01:00
|
|
|
* @param array $config An ESI configuration array
|
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
2011-01-17 15:21:46 +00: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 registerEsiConfiguration(array $config, XmlFileLoader $loader)
|
2011-01-17 15:21:46 +00:00
|
|
|
{
|
2011-02-10 20:40:00 +00:00
|
|
|
if (!empty($config['enabled'])) {
|
2011-01-24 19:50:31 +00:00
|
|
|
$loader->load('esi.xml');
|
2011-01-17 15:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 08:46:15 +01:00
|
|
|
/**
|
2011-01-24 19:50:31 +00:00
|
|
|
* Loads the profiler configuration.
|
2010-09-27 08:46:15 +01:00
|
|
|
*
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param array $config A profiler configuration array
|
2010-09-27 08:46:15 +01:00
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
2010-09-27 08:46:15 +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 registerProfilerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
2010-09-27 08:46:15 +01:00
|
|
|
{
|
2011-02-05 21:19:14 +00:00
|
|
|
$loader->load('profiling.xml');
|
|
|
|
$loader->load('collectors.xml');
|
2010-09-27 08:46:15 +01:00
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
|
|
|
|
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);
|
2011-03-16 14:50:48 +00:00
|
|
|
|
|
|
|
// Choose storage class based on the DSN
|
|
|
|
$supported = array(
|
2011-12-01 21:18:49 +00:00
|
|
|
'sqlite' => 'Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage',
|
|
|
|
'mysql' => 'Symfony\Component\HttpKernel\Profiler\MysqlProfilerStorage',
|
|
|
|
'file' => 'Symfony\Component\HttpKernel\Profiler\FileProfilerStorage',
|
|
|
|
'mongodb' => 'Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage',
|
|
|
|
'memcache' => 'Symfony\Component\HttpKernel\Profiler\MemcacheProfilerStorage',
|
|
|
|
'memcached' => 'Symfony\Component\HttpKernel\Profiler\MemcachedProfilerStorage',
|
2012-02-26 00:09:51 +00:00
|
|
|
'redis' => 'Symfony\Component\HttpKernel\Profiler\RedisProfilerStorage',
|
2011-03-16 14:50:48 +00:00
|
|
|
);
|
2011-12-03 20:36:39 +00:00
|
|
|
list($class, ) = explode(':', $config['dsn'], 2);
|
2011-03-16 14:50:48 +00:00
|
|
|
if (!isset($supported[$class])) {
|
|
|
|
throw new \LogicException(sprintf('Driver "%s" is not supported for the profiler.', $class));
|
2011-02-05 21:19:14 +00:00
|
|
|
}
|
2010-09-27 15:53:23 +01:00
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('profiler.storage.dsn', $config['dsn']);
|
|
|
|
$container->setParameter('profiler.storage.username', $config['username']);
|
|
|
|
$container->setParameter('profiler.storage.password', $config['password']);
|
|
|
|
$container->setParameter('profiler.storage.lifetime', $config['lifetime']);
|
|
|
|
|
|
|
|
$container->getDefinition('profiler.storage')->setClass($supported[$class]);
|
2010-09-27 15:53:23 +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
|
|
|
if (isset($config['matcher'])) {
|
2011-02-05 21:19:14 +00:00
|
|
|
if (isset($config['matcher']['service'])) {
|
|
|
|
$container->setAlias('profiler.request_matcher', $config['matcher']['service']);
|
|
|
|
} elseif (isset($config['matcher']['ip']) || isset($config['matcher']['path'])) {
|
|
|
|
$definition = $container->register('profiler.request_matcher', 'Symfony\\Component\\HttpFoundation\\RequestMatcher');
|
|
|
|
$definition->setPublic(false);
|
2010-09-27 08:46:15 +01:00
|
|
|
|
2011-02-05 21:19:14 +00:00
|
|
|
if (isset($config['matcher']['ip'])) {
|
|
|
|
$definition->addMethodCall('matchIp', array($config['matcher']['ip']));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['matcher']['path'])) {
|
|
|
|
$definition->addMethodCall('matchPath', array($config['matcher']['path']));
|
2010-09-27 08:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-15 19:49:16 +01:00
|
|
|
/**
|
2011-01-24 19:50:31 +00:00
|
|
|
* Loads the router configuration.
|
2010-09-15 19:49:16 +01:00
|
|
|
*
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param array $config A router configuration array
|
2010-09-15 19:49:16 +01:00
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
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)
|
2010-09-15 19:49:16 +01:00
|
|
|
{
|
2011-01-24 19:50:31 +00:00
|
|
|
$loader->load('routing.xml');
|
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('router.resource', $config['resource']);
|
2011-07-18 09:05:28 +01:00
|
|
|
$router = $container->findDefinition('router.default');
|
2010-11-12 18:35:21 +00:00
|
|
|
|
2011-02-10 15:26:13 +00:00
|
|
|
if (isset($config['type'])) {
|
2011-04-28 10:26:10 +01:00
|
|
|
$argument = $router->getArgument(2);
|
|
|
|
$argument['resource_type'] = $config['type'];
|
|
|
|
$router->replaceArgument(2, $argument);
|
2011-02-10 15:26:13 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('request_listener.http_port', $config['http_port']);
|
|
|
|
$container->setParameter('request_listener.https_port', $config['https_port']);
|
2011-04-19 23:25:45 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
$this->addClassesToCompile(array(
|
|
|
|
'Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface',
|
|
|
|
'Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface',
|
2011-07-21 20:44:10 +01:00
|
|
|
'Symfony\\Component\\Routing\\RouterInterface',
|
|
|
|
'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
|
2011-01-24 19:50:31 +00:00
|
|
|
'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Component\\Routing\\Matcher\\RedirectableUrlMatcherInterface',
|
|
|
|
'Symfony\\Component\\Routing\\RequestContextAwareInterface',
|
|
|
|
'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(),
|
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)
|
2011-01-24 19:50:31 +00:00
|
|
|
{
|
|
|
|
$loader->load('session.xml');
|
2011-01-23 07:36:19 +00:00
|
|
|
|
2011-04-22 11:35:09 +01:00
|
|
|
// session
|
2011-07-15 09:23:38 +01:00
|
|
|
$container->getDefinition('session_listener')->addArgument($config['auto_start']);
|
2010-11-25 18:07:25 +00:00
|
|
|
|
2011-04-22 11:35:09 +01:00
|
|
|
// session storage
|
|
|
|
$container->setAlias('session.storage', $config['storage_id']);
|
|
|
|
$options = array();
|
2012-03-21 03:22:23 +00:00
|
|
|
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'auto_start', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
|
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];
|
2010-12-14 14:51:10 +00:00
|
|
|
}
|
2010-09-15 19:49:16 +01:00
|
|
|
}
|
2012-02-29 08:44:47 +00:00
|
|
|
|
|
|
|
//we deprecated session options without cookie_ prefix, but we are still supporting them,
|
|
|
|
//Let's merge the ones that were supplied without prefix
|
2012-02-23 10:53:14 +00:00
|
|
|
foreach (array('lifetime', 'path', 'domain', 'secure', 'httponly') as $key) {
|
2012-02-29 08:44:47 +00:00
|
|
|
if (!isset($options['cookie_'.$key]) && isset($config[$key])) {
|
2012-02-23 10:53:14 +00:00
|
|
|
$options['cookie_'.$key] = $config[$key];
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 11:35:09 +01:00
|
|
|
$container->setParameter('session.storage.options', $options);
|
2010-11-25 08:04:24 +00:00
|
|
|
|
2012-03-03 09:03:04 +00:00
|
|
|
// session handler (the internal callback registered with PHP session management)
|
|
|
|
$container->setAlias('session.handler', $config['handler_id']);
|
|
|
|
|
2012-04-13 09:34:00 +01:00
|
|
|
$container->setParameter('session.save_path', $config['save_path']);
|
|
|
|
|
2011-01-16 09:17:38 +00:00
|
|
|
$this->addClassesToCompile(array(
|
2011-05-31 09:09:25 +01:00
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener',
|
2012-02-11 11:21:08 +00:00
|
|
|
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface',
|
2012-03-14 15:14:09 +00:00
|
|
|
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage',
|
2012-03-03 09:03:04 +00:00
|
|
|
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\NativeSessionHandler',
|
|
|
|
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\AbstractProxy',
|
|
|
|
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\SessionHandlerProxy',
|
2011-04-23 10:43:35 +01:00
|
|
|
$container->getDefinition('session')->getClass(),
|
2010-11-25 08:04:24 +00:00
|
|
|
));
|
2011-04-28 10:27:56 +01:00
|
|
|
|
|
|
|
if ($container->hasDefinition($config['storage_id'])) {
|
|
|
|
$this->addClassesToCompile(array(
|
|
|
|
$container->findDefinition('session.storage')->getClass(),
|
|
|
|
));
|
|
|
|
}
|
2010-09-15 19:49:16 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 15:58:07 +00:00
|
|
|
/**
|
2011-01-24 19:50:31 +00:00
|
|
|
* Loads the templating configuration.
|
2011-01-11 15:58:07 +00:00
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param array $config A templating configuration array
|
2011-04-23 16:05:44 +01:00
|
|
|
* @param string $ide
|
2011-01-11 15:58:07 +00:00
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
2011-01-11 15:58:07 +00:00
|
|
|
*/
|
2011-04-05 07:03:29 +01:00
|
|
|
private function registerTemplatingConfiguration(array $config, $ide, ContainerBuilder $container, XmlFileLoader $loader)
|
2010-09-20 20:01:41 +01:00
|
|
|
{
|
2011-01-24 19:50:31 +00:00
|
|
|
$loader->load('templating.xml');
|
|
|
|
$loader->load('templating_php.xml');
|
|
|
|
|
2011-04-05 07:03:29 +01:00
|
|
|
$links = array(
|
2011-07-12 18:01:49 +01:00
|
|
|
'textmate' => 'txmt://open?url=file://%%f&line=%%l',
|
|
|
|
'macvim' => 'mvim://open?url=file://%%f&line=%%l',
|
2011-04-05 07:03:29 +01:00
|
|
|
);
|
|
|
|
|
2011-07-12 18:01:49 +01:00
|
|
|
$container->setParameter('templating.helper.code.file_link_format', isset($links[$ide]) ? $links[$ide] : $ide);
|
2011-06-22 07:27:40 +01:00
|
|
|
$container->setParameter('templating.helper.form.resources', $config['form']['resources']);
|
2011-12-16 14:51:05 +00:00
|
|
|
$container->setParameter('templating.hinclude.default_template', $config['hinclude_default_template']);
|
2011-04-05 07:03:29 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
if ($container->getParameter('kernel.debug')) {
|
|
|
|
$loader->load('templating_debug.xml');
|
2010-09-20 20:01:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-21 00:08:03 +01:00
|
|
|
// create package definitions and add them to the assets helper
|
|
|
|
$defaultPackage = $this->createPackageDefinition($container, $config['assets_base_urls']['http'], $config['assets_base_urls']['ssl'], $config['assets_version'], $config['assets_version_format']);
|
|
|
|
$container->setDefinition('templating.asset.default_package', $defaultPackage);
|
|
|
|
$namedPackages = array();
|
2011-03-08 17:22:25 +00:00
|
|
|
foreach ($config['packages'] as $name => $package) {
|
2011-05-21 00:08:03 +01:00
|
|
|
$namedPackage = $this->createPackageDefinition($container, $package['base_urls']['http'], $package['base_urls']['ssl'], $package['version'], $package['version_format'], $name);
|
|
|
|
$container->setDefinition('templating.asset.package.'.$name, $namedPackage);
|
|
|
|
$namedPackages[$name] = new Reference('templating.asset.package.'.$name);
|
2011-03-08 17:22:25 +00:00
|
|
|
}
|
2011-05-21 00:08:03 +01:00
|
|
|
$container->getDefinition('templating.helper.assets')->setArguments(array(
|
|
|
|
new Reference('templating.asset.default_package'),
|
|
|
|
$namedPackages,
|
|
|
|
));
|
2011-03-08 17:22:25 +00:00
|
|
|
|
2011-09-26 18:19:08 +01:00
|
|
|
// Apply request scope to assets helper if one or more packages are request-scoped
|
|
|
|
$requireRequestScope = array_reduce(
|
|
|
|
$namedPackages,
|
|
|
|
function($v, Reference $ref) use ($container) {
|
|
|
|
return $v || 'request' === $container->getDefinition($ref)->getScope();
|
|
|
|
},
|
|
|
|
'request' === $defaultPackage->getScope()
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($requireRequestScope) {
|
|
|
|
$container->getDefinition('templating.helper.assets')->setScope('request');
|
|
|
|
}
|
|
|
|
|
2011-02-10 20:40:00 +00:00
|
|
|
if (!empty($config['loaders'])) {
|
2011-01-24 19:50:31 +00:00
|
|
|
$loaders = array_map(function($loader) { return new Reference($loader); }, $config['loaders']);
|
|
|
|
|
2011-02-06 20:39:30 +00:00
|
|
|
// Use a delegation unless only a single loader was registered
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$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'])) {
|
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'));
|
2011-04-04 10:56:41 +01:00
|
|
|
$loaderCache = $container->getDefinition('templating.loader.cache');
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('templating.loader.cache.path', $config['cache']);
|
2011-04-04 10:56:41 +01:00
|
|
|
|
|
|
|
$container->setDefinition('templating.loader', $loaderCache);
|
2011-01-24 19:50:31 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 09:17:38 +00:00
|
|
|
$this->addClassesToCompile(array(
|
2011-07-21 21:32:50 +01:00
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables',
|
2011-01-24 19:50:31 +00:00
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface',
|
2011-12-31 09:50:19 +00:00
|
|
|
'Symfony\\Component\\Templating\\StreamingEngineInterface',
|
2011-02-10 17:20:44 +00:00
|
|
|
'Symfony\\Component\\Templating\\TemplateNameParserInterface',
|
|
|
|
'Symfony\\Component\\Templating\\TemplateNameParser',
|
2011-01-24 19:50:31 +00:00
|
|
|
'Symfony\\Component\\Templating\\EngineInterface',
|
2011-02-10 15:15:51 +00:00
|
|
|
'Symfony\\Component\\Config\\FileLocatorInterface',
|
2011-02-10 17:20:44 +00:00
|
|
|
'Symfony\\Component\\Templating\\TemplateReferenceInterface',
|
|
|
|
'Symfony\\Component\\Templating\\TemplateReference',
|
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\TemplateReference',
|
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\TemplateNameParser',
|
2011-01-24 19:50:31 +00:00
|
|
|
$container->findDefinition('templating.locator')->getClass(),
|
2010-09-20 20:01:41 +01:00
|
|
|
));
|
2011-01-24 19:50:31 +00:00
|
|
|
|
|
|
|
if (in_array('php', $config['engines'], true)) {
|
|
|
|
$this->addClassesToCompile(array(
|
|
|
|
'Symfony\\Component\\Templating\\PhpEngine',
|
|
|
|
'Symfony\\Component\\Templating\\Loader\\LoaderInterface',
|
|
|
|
'Symfony\\Component\\Templating\\Storage\\Storage',
|
|
|
|
'Symfony\\Component\\Templating\\Storage\\FileStorage',
|
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\PhpEngine',
|
|
|
|
'Symfony\\Bundle\\FrameworkBundle\\Templating\\Loader\\FilesystemLoader',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-02-10 21:05:04 +00:00
|
|
|
$container->setParameter('templating.engines', $config['engines']);
|
2011-01-24 19:50:31 +00:00
|
|
|
$engines = array_map(function($engine) { return new Reference('templating.engine.'.$engine); }, $config['engines']);
|
|
|
|
|
2011-02-26 17:41:17 +00:00
|
|
|
// Use a delegation unless only a single engine was registered
|
2011-01-24 19:50:31 +00:00
|
|
|
if (1 === count($engines)) {
|
|
|
|
$container->setAlias('templating', (string) reset($engines));
|
|
|
|
} else {
|
2011-04-19 22:29:10 +01:00
|
|
|
$container->getDefinition('templating.engine.delegating')->replaceArgument(1, $engines);
|
2011-01-24 19:50:31 +00:00
|
|
|
$container->setAlias('templating', 'templating.engine.delegating');
|
|
|
|
}
|
2010-09-20 20:01:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-21 00:08:03 +01:00
|
|
|
/**
|
|
|
|
* Returns a definition for an asset package.
|
|
|
|
*/
|
|
|
|
private function createPackageDefinition(ContainerBuilder $container, array $httpUrls, array $sslUrls, $version, $format, $name = null)
|
|
|
|
{
|
|
|
|
if (!$httpUrls) {
|
|
|
|
$package = new DefinitionDecorator('templating.asset.path_package');
|
|
|
|
$package
|
|
|
|
->setPublic(false)
|
|
|
|
->setScope('request')
|
|
|
|
->replaceArgument(1, $version)
|
|
|
|
->replaceArgument(2, $format)
|
|
|
|
;
|
|
|
|
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($httpUrls == $sslUrls) {
|
|
|
|
$package = new DefinitionDecorator('templating.asset.url_package');
|
|
|
|
$package
|
|
|
|
->setPublic(false)
|
|
|
|
->replaceArgument(0, $sslUrls)
|
|
|
|
->replaceArgument(1, $version)
|
|
|
|
->replaceArgument(2, $format)
|
|
|
|
;
|
|
|
|
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
|
|
|
|
$prefix = $name ? 'templating.asset.package.'.$name : 'templating.asset.default_package';
|
|
|
|
|
|
|
|
$httpPackage = new DefinitionDecorator('templating.asset.url_package');
|
|
|
|
$httpPackage
|
|
|
|
->replaceArgument(0, $httpUrls)
|
|
|
|
->replaceArgument(1, $version)
|
|
|
|
->replaceArgument(2, $format)
|
|
|
|
;
|
|
|
|
$container->setDefinition($prefix.'.http', $httpPackage);
|
|
|
|
|
|
|
|
if ($sslUrls) {
|
|
|
|
$sslPackage = new DefinitionDecorator('templating.asset.url_package');
|
|
|
|
$sslPackage
|
|
|
|
->replaceArgument(0, $sslUrls)
|
|
|
|
->replaceArgument(1, $version)
|
|
|
|
->replaceArgument(2, $format)
|
|
|
|
;
|
|
|
|
} else {
|
|
|
|
$sslPackage = new DefinitionDecorator('templating.asset.path_package');
|
|
|
|
$sslPackage
|
|
|
|
->setScope('request')
|
|
|
|
->replaceArgument(1, $version)
|
|
|
|
->replaceArgument(2, $format)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
$container->setDefinition($prefix.'.ssl', $sslPackage);
|
|
|
|
|
|
|
|
$package = new DefinitionDecorator('templating.asset.request_aware_package');
|
|
|
|
$package
|
|
|
|
->setPublic(false)
|
|
|
|
->setScope('request')
|
|
|
|
->replaceArgument(1, $prefix.'.http')
|
|
|
|
->replaceArgument(2, $prefix.'.ssl')
|
|
|
|
;
|
|
|
|
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
|
2011-01-11 15:58:07 +00:00
|
|
|
/**
|
2011-01-24 19:50:31 +00:00
|
|
|
* Loads the translator configuration.
|
2011-01-11 15:58:07 +00:00
|
|
|
*
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param array $config A translator configuration array
|
2011-01-11 15:58:07 +00:00
|
|
|
* @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)
|
2010-09-02 12:54:32 +01:00
|
|
|
{
|
2011-02-10 20:40:00 +00:00
|
|
|
if (!empty($config['enabled'])) {
|
2011-01-24 19:50:31 +00:00
|
|
|
// Use the "real" translator instead of the identity default
|
2011-07-19 11:05:51 +01:00
|
|
|
$container->setAlias('translator', 'translator.default');
|
|
|
|
$translator = $container->findDefinition('translator.default');
|
2011-03-30 18:16:13 +01:00
|
|
|
$translator->addMethodCall('setFallbackLocale', array($config['fallback']));
|
2010-09-02 12:54:32 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
// Discover translation directories
|
|
|
|
$dirs = array();
|
2012-04-20 13:17:18 +01:00
|
|
|
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
|
|
|
|
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
|
|
|
|
$reflection = new \ReflectionClass($class);
|
2011-01-24 19:50:31 +00:00
|
|
|
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
|
|
|
|
$dirs[] = $dir;
|
|
|
|
}
|
2012-04-20 13:17:18 +01:00
|
|
|
if (is_dir($dir = sprintf($overridePath, $bundle))) {
|
|
|
|
$dirs[] = $dir;
|
|
|
|
}
|
2011-01-24 19:50:31 +00:00
|
|
|
}
|
2011-04-29 16:48:38 +01:00
|
|
|
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
|
2011-01-24 19:50:31 +00:00
|
|
|
$dirs[] = $dir;
|
|
|
|
}
|
2010-09-02 12:54:32 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
// Register translation resources
|
|
|
|
if ($dirs) {
|
2012-04-20 14:14:14 +01:00
|
|
|
foreach ($dirs as $dir) {
|
|
|
|
$container->addResource(new DirectoryResource($dir));
|
|
|
|
}
|
2012-04-20 13:17:18 +01:00
|
|
|
$finder = Finder::create()
|
|
|
|
->files()
|
|
|
|
->filter(function (\SplFileInfo $file) {
|
|
|
|
return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
|
|
|
|
})
|
|
|
|
->in($dirs)
|
|
|
|
;
|
2012-04-25 11:14:55 +01:00
|
|
|
|
2011-01-24 19:50:31 +00:00
|
|
|
foreach ($finder as $file) {
|
|
|
|
// filename is domain.locale.format
|
2011-12-11 20:16:22 +00:00
|
|
|
list($domain, $locale, $format) = explode('.', $file->getBasename(), 3);
|
2011-04-23 10:34:17 +01:00
|
|
|
$translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
|
2010-09-02 12:54:32 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-24 19:50:31 +00:00
|
|
|
}
|
2010-09-02 12:54:32 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 15:58:07 +00:00
|
|
|
/**
|
|
|
|
* Loads the validator configuration.
|
|
|
|
*
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param array $config A validation configuration array
|
2011-01-11 15:58:07 +00:00
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance
|
2011-01-24 19:50:31 +00:00
|
|
|
* @param XmlFileLoader $loader An XmlFileLoader instance
|
2011-01-11 15:58:07 +00: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 registerValidationConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
|
2010-08-18 13:44:35 +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
|
|
|
$loader->load('validator.xml');
|
2010-08-18 13:44:35 +01:00
|
|
|
|
2011-05-13 10:57:05 +01:00
|
|
|
$container->setParameter('validator.mapping.loader.xml_files_loader.mapping_files', $this->getValidatorXmlMappingFiles($container));
|
|
|
|
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $this->getValidatorYamlMappingFiles($container));
|
2010-08-18 13:44:35 +01:00
|
|
|
|
2011-08-04 11:56:01 +01:00
|
|
|
if (array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
|
[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
|
|
|
$loaderChain = $container->getDefinition('validator.mapping.loader.loader_chain');
|
|
|
|
$arguments = $loaderChain->getArguments();
|
|
|
|
array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader'));
|
|
|
|
$loaderChain->setArguments($arguments);
|
2010-08-18 13:44:35 +01:00
|
|
|
}
|
2011-03-29 22:07:50 +01:00
|
|
|
|
|
|
|
if (isset($config['cache'])) {
|
|
|
|
$container->getDefinition('validator.mapping.class_metadata_factory')
|
2011-04-19 22:29:10 +01:00
|
|
|
->replaceArgument(1, new Reference('validator.mapping.cache.'.$config['cache']));
|
2011-03-29 22:07:50 +01:00
|
|
|
$container->setParameter(
|
|
|
|
'validator.mapping.cache.prefix',
|
|
|
|
'validator_'.md5($container->getParameter('kernel.root_dir'))
|
|
|
|
);
|
|
|
|
}
|
2010-08-18 13:44:35 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:26:19 +01:00
|
|
|
private function getValidatorXmlMappingFiles(ContainerBuilder $container)
|
|
|
|
{
|
2012-01-17 09:27:14 +00:00
|
|
|
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
|
2012-01-17 09:55:12 +00:00
|
|
|
$files = array(dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
|
2011-04-01 07:26:19 +01:00
|
|
|
$container->addResource(new FileResource($files[0]));
|
|
|
|
|
|
|
|
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
|
|
|
$reflection = new \ReflectionClass($bundle);
|
2011-08-29 14:28:03 +01:00
|
|
|
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
|
2011-04-01 07:26:19 +01:00
|
|
|
$files[] = realpath($file);
|
|
|
|
$container->addResource(new FileResource($file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getValidatorYamlMappingFiles(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$files = array();
|
|
|
|
|
|
|
|
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
|
|
|
$reflection = new \ReflectionClass($bundle);
|
2011-08-29 14:28:03 +01:00
|
|
|
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) {
|
2011-04-11 22:26:11 +01:00
|
|
|
$files[] = realpath($file);
|
2011-04-01 07:26:19 +01:00
|
|
|
$container->addResource(new FileResource($file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
2011-05-03 13:36:42 +01:00
|
|
|
private function registerAnnotationsConfiguration(array $config, ContainerBuilder $container,$loader)
|
|
|
|
{
|
|
|
|
$loader->load('annotations.xml');
|
|
|
|
|
|
|
|
if ('file' === $config['cache']) {
|
2011-05-24 12:29:44 +01:00
|
|
|
$cacheDir = $container->getParameterBag()->resolveValue($config['file_cache_dir']);
|
2011-05-03 13:36:42 +01:00
|
|
|
if (!is_dir($cacheDir) && false === @mkdir($cacheDir, 0777, true)) {
|
|
|
|
throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
|
|
|
|
}
|
|
|
|
|
|
|
|
$container
|
2011-05-24 12:29:44 +01:00
|
|
|
->getDefinition('annotations.file_cache_reader')
|
|
|
|
->replaceArgument(1, $cacheDir)
|
|
|
|
->replaceArgument(2, $config['debug'])
|
2011-05-03 13:36:42 +01:00
|
|
|
;
|
2011-05-24 12:29:44 +01:00
|
|
|
$container->setAlias('annotation_reader', 'annotations.file_cache_reader');
|
2012-05-01 13:46:26 +01:00
|
|
|
} elseif ('none' !== $config['cache']) {
|
2011-05-03 13:36:42 +01:00
|
|
|
$container
|
|
|
|
->getDefinition('annotations.cached_reader')
|
|
|
|
->replaceArgument(1, new Reference($config['cache']))
|
2011-05-24 12:29:44 +01:00
|
|
|
->replaceArgument(2, $config['debug'])
|
2011-05-03 13:36:42 +01:00
|
|
|
;
|
2011-05-24 12:29:44 +01:00
|
|
|
$container->setAlias('annotation_reader', 'annotations.cached_reader');
|
2011-05-03 13:36:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Returns the base path for the XSD files.
|
|
|
|
*
|
|
|
|
* @return string The XSD base path
|
|
|
|
*/
|
|
|
|
public function getXsdValidationBasePath()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-06-27 17:54:03 +01:00
|
|
|
return __DIR__.'/../Resources/config/schema';
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getNamespace()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2011-03-06 11:40:06 +00:00
|
|
|
return 'http://symfony.com/schema/dic/symfony';
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
}
|