2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
2010-07-09 09:05:26 +01:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2011-01-05 19:53:38 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
|
2011-01-13 13:58:17 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
2011-01-05 11:13:27 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass;
|
2010-12-20 19:56:14 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
|
2010-12-23 08:56:38 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConverterManagerPass;
|
2010-12-23 11:32:51 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
|
2010-12-23 11:48:45 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
2011-01-16 09:17:38 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToCachePass;
|
2011-01-17 10:29:38 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
|
2010-12-20 19:56:14 +00:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-01-16 09:17:38 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
2010-09-15 19:49:16 +01:00
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
2010-11-25 08:30:18 +00:00
|
|
|
use Symfony\Component\Form\FormConfiguration;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* Bundle.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-02-17 13:55:05 +00:00
|
|
|
*/
|
2010-07-09 09:05:26 +01:00
|
|
|
class FrameworkBundle extends Bundle
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-09-10 13:32:33 +01:00
|
|
|
/**
|
|
|
|
* Boots the Bundle.
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2010-09-15 19:49:16 +01:00
|
|
|
if ($this->container->has('error_handler')) {
|
2010-11-15 10:13:01 +00:00
|
|
|
$this->container->get('error_handler');
|
2010-09-15 19:49:16 +01:00
|
|
|
}
|
2011-01-11 17:14:39 +00:00
|
|
|
|
|
|
|
FormConfiguration::clearDefaultCsrfSecrets();
|
|
|
|
|
2010-09-10 18:32:17 +01:00
|
|
|
if ($this->container->hasParameter('csrf_secret')) {
|
2011-01-03 16:00:28 +00:00
|
|
|
FormConfiguration::addDefaultCsrfSecret($this->container->getParameter('csrf_secret'));
|
2010-11-25 08:30:18 +00:00
|
|
|
FormConfiguration::enableDefaultCsrfProtection();
|
2010-09-10 13:32:33 +01:00
|
|
|
}
|
2011-01-03 16:00:28 +00:00
|
|
|
|
|
|
|
// the session ID should always be included in the CSRF token, even
|
|
|
|
// if default CSRF protection is not enabled
|
2011-01-17 16:44:23 +00:00
|
|
|
if ($this->container->has('session')) {
|
|
|
|
$container = $this->container;
|
|
|
|
FormConfiguration::addDefaultCsrfSecret(function () use ($container) {
|
|
|
|
// automatically starts the session when the CSRF token is
|
|
|
|
// generated
|
|
|
|
$container->get('session')->start();
|
2011-01-03 16:00:28 +00:00
|
|
|
|
2011-01-17 16:44:23 +00:00
|
|
|
return $container->get('session')->getId();
|
|
|
|
});
|
|
|
|
}
|
2010-09-10 13:32:33 +01:00
|
|
|
}
|
2010-12-20 19:56:14 +00:00
|
|
|
|
|
|
|
public function registerExtensions(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
parent::registerExtensions($container);
|
|
|
|
|
|
|
|
$container->addCompilerPass(new AddSecurityVotersPass());
|
2010-12-23 08:56:38 +00:00
|
|
|
$container->addCompilerPass(new ConverterManagerPass());
|
2010-12-23 11:32:51 +00:00
|
|
|
$container->addCompilerPass(new RoutingResolverPass());
|
2010-12-23 11:48:45 +00:00
|
|
|
$container->addCompilerPass(new ProfilerPass());
|
2011-01-05 11:13:27 +00:00
|
|
|
$container->addCompilerPass(new RegisterKernelListenersPass());
|
2011-01-13 13:58:17 +00:00
|
|
|
$container->addCompilerPass(new TemplatingPass());
|
2011-01-05 19:53:38 +00:00
|
|
|
$container->addCompilerPass(new AddConstraintValidatorsPass());
|
2011-01-16 09:17:38 +00:00
|
|
|
$container->addCompilerPass(new AddClassesToCachePass());
|
2011-01-17 10:29:38 +00:00
|
|
|
$container->addCompilerPass(new TranslatorPass());
|
2010-12-20 19:56:14 +00:00
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|