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;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2017-01-23 20:50:14 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
2016-11-04 20:47:40 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
|
2016-12-27 15:06:31 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPass;
|
2016-03-04 17:43:16 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
|
2016-09-10 10:05:01 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
|
2017-02-16 20:43:11 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
2011-01-13 13:58:17 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
2010-12-23 11:48:45 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
2014-05-10 23:14:12 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
|
2014-09-25 16:27:00 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
|
2011-03-10 15:09:40 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
|
2014-10-29 09:15:52 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
2017-01-22 22:45:08 +00:00
|
|
|
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
|
2016-07-27 09:24:18 +01:00
|
|
|
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
2017-05-03 13:00:53 +01:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass;
|
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass;
|
2017-02-21 21:38:27 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
|
2017-02-26 16:28:32 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
|
2017-02-20 18:49:52 +00:00
|
|
|
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
|
2017-02-20 19:19:16 +00:00
|
|
|
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
|
2017-01-14 18:54:56 +00:00
|
|
|
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
|
2014-10-02 16:46:44 +01:00
|
|
|
use Symfony\Component\Debug\ErrorHandler;
|
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;
|
2013-12-16 17:44:05 +00:00
|
|
|
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
|
2015-01-10 22:10:57 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
2017-01-13 19:57:15 +00:00
|
|
|
use Symfony\Component\Form\DependencyInjection\FormPass;
|
2011-07-05 18:38:29 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2010-09-15 19:49:16 +01:00
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
2017-01-13 19:57:15 +00:00
|
|
|
use Symfony\Component\Config\Resource\ClassExistenceResource;
|
2017-05-05 11:35:04 +01:00
|
|
|
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
|
|
|
|
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
|
|
|
|
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
2017-02-22 23:37:05 +00:00
|
|
|
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
|
|
|
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
|
2017-04-06 09:44:15 +01:00
|
|
|
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass;
|
2010-02-17 13:55:05 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* Bundle.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.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
|
|
|
{
|
2011-07-05 18:38:29 +01:00
|
|
|
public function boot()
|
|
|
|
{
|
2014-10-27 13:40:25 +00:00
|
|
|
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
|
2014-10-02 16:46:44 +01:00
|
|
|
|
2013-02-27 13:12:14 +00:00
|
|
|
if ($this->container->getParameter('kernel.http_method_override')) {
|
|
|
|
Request::enableHttpMethodParameterOverride();
|
|
|
|
}
|
2013-08-06 08:14:49 +01:00
|
|
|
|
|
|
|
if ($trustedHosts = $this->container->getParameter('kernel.trusted_hosts')) {
|
|
|
|
Request::setTrustedHosts($trustedHosts);
|
|
|
|
}
|
2011-07-05 18:38:29 +01:00
|
|
|
}
|
|
|
|
|
2011-02-15 03:47:19 +00:00
|
|
|
public function build(ContainerBuilder $container)
|
2010-12-20 19:56:14 +00:00
|
|
|
{
|
2011-02-15 03:47:19 +00:00
|
|
|
parent::build($container);
|
2010-12-20 19:56:14 +00:00
|
|
|
|
2017-02-26 16:28:32 +00:00
|
|
|
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
|
|
|
|
$container->addCompilerPass(new RemoveEmptyControllerArgumentLocatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
2010-12-23 11:32:51 +00:00
|
|
|
$container->addCompilerPass(new RoutingResolverPass());
|
2010-12-23 11:48:45 +00:00
|
|
|
$container->addCompilerPass(new ProfilerPass());
|
2013-09-12 13:08:32 +01:00
|
|
|
// must be registered before removing private services as some might be listeners/subscribers
|
|
|
|
// but as late as possible to get resolved parameters
|
2013-09-12 13:57:47 +01:00
|
|
|
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
2011-01-13 13:58:17 +00:00
|
|
|
$container->addCompilerPass(new TemplatingPass());
|
2017-02-22 23:37:05 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class, PassConfig::TYPE_BEFORE_REMOVING);
|
2017-01-23 20:50:14 +00:00
|
|
|
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
2017-02-22 23:37:05 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
|
2017-02-16 13:36:15 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
|
2017-05-05 11:35:04 +01:00
|
|
|
$this->addCompilerPassIfExists($container, TranslatorPass::class);
|
2014-05-10 23:14:12 +01:00
|
|
|
$container->addCompilerPass(new LoggingTranslatorPass());
|
2011-01-24 10:16:22 +00:00
|
|
|
$container->addCompilerPass(new AddCacheWarmerPass());
|
2011-12-12 22:39:17 +00:00
|
|
|
$container->addCompilerPass(new AddCacheClearerPass());
|
2014-09-25 16:27:00 +01:00
|
|
|
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
2017-05-05 11:35:04 +01:00
|
|
|
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
|
|
|
|
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
|
2013-01-31 09:37:27 +00:00
|
|
|
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2017-02-16 13:36:15 +00:00
|
|
|
$this->addCompilerPassIfExists($container, SerializerPass::class);
|
2017-02-20 18:49:52 +00:00
|
|
|
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
|
2017-02-16 20:43:11 +00:00
|
|
|
$container->addCompilerPass(new DataCollectorTranslatorPass());
|
2016-03-25 09:46:04 +00:00
|
|
|
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
|
2016-11-23 08:28:29 +00:00
|
|
|
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
|
2017-04-06 09:44:15 +01:00
|
|
|
$this->addCompilerPassIfExists($container, ValidateWorkflowsPass::class);
|
2016-09-10 10:05:01 +01:00
|
|
|
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2017-01-13 19:57:15 +00:00
|
|
|
$this->addCompilerPassIfExists($container, FormPass::class);
|
2011-04-15 09:14:13 +01:00
|
|
|
|
|
|
|
if ($container->getParameter('kernel.debug')) {
|
2016-11-23 08:28:29 +00:00
|
|
|
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
|
2015-09-28 12:00:47 +01:00
|
|
|
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2017-04-10 10:03:54 +01:00
|
|
|
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
|
2017-01-22 22:45:08 +00:00
|
|
|
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
|
2017-06-01 16:20:33 +01:00
|
|
|
$container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
2011-04-15 09:14:13 +01:00
|
|
|
}
|
2010-12-20 19:56:14 +00:00
|
|
|
}
|
2017-01-13 19:57:15 +00:00
|
|
|
|
|
|
|
private function addCompilerPassIfExists(ContainerBuilder $container, $class, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0)
|
|
|
|
{
|
|
|
|
$container->addResource(new ClassExistenceResource($class));
|
|
|
|
|
|
|
|
if (class_exists($class)) {
|
|
|
|
$container->addCompilerPass(new $class(), $type, $priority);
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|