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;
|
2018-07-26 10:03:18 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
|
2017-02-16 20:43:11 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
2014-05-10 23:14:12 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
|
2018-07-26 10:03:18 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
2018-03-12 19:13:33 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
|
2018-07-26 10:10:45 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
|
2014-10-29 09:15:52 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
2017-07-21 19:01:38 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
|
2018-07-11 13:10:39 +01:00
|
|
|
use Symfony\Component\Cache\DependencyInjection\CacheCollectorPass;
|
|
|
|
use Symfony\Component\Cache\DependencyInjection\CachePoolClearerPass;
|
|
|
|
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
|
|
|
|
use Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass;
|
2018-07-26 10:06:28 +01:00
|
|
|
use Symfony\Component\Config\Resource\ClassExistenceResource;
|
2016-07-27 09:24:18 +01:00
|
|
|
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
2011-01-16 09:17:38 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
2019-02-21 10:17:27 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Compiler\RegisterReverseContainerPass;
|
2018-07-26 10:03:18 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2019-06-27 17:12:00 +01:00
|
|
|
use Symfony\Component\ErrorCatcher\DependencyInjection\ErrorCatcherPass;
|
|
|
|
use Symfony\Component\ErrorCatcher\ErrorHandler;
|
2013-12-16 17:44:05 +00:00
|
|
|
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
|
2018-07-26 10:06:28 +01: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-02-21 21:38:27 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
|
2018-07-26 10:03:18 +01:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
2017-09-23 14:20:05 +01:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
|
2017-02-26 16:28:32 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
2018-10-10 23:18:00 +01:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\RegisterLocaleAwareServicesPass;
|
2017-02-26 16:28:32 +00:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
|
2017-09-11 15:29:04 +01:00
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
|
2018-07-26 10:06:28 +01:00
|
|
|
use Symfony\Component\HttpKernel\KernelEvents;
|
2017-09-30 13:16:30 +01:00
|
|
|
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
|
2019-01-27 10:52:17 +00:00
|
|
|
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
|
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;
|
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;
|
2019-02-08 17:17:48 +00:00
|
|
|
use Symfony\Component\Translation\DependencyInjection\TranslatorPathsPass;
|
2018-06-26 16:35:39 +01:00
|
|
|
use Symfony\Component\Validator\DependencyInjection\AddAutoMappingConfigurationPass;
|
2017-02-22 23:37:05 +00:00
|
|
|
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
|
|
|
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
|
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
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$hotPathEvents = [
|
2017-11-08 09:48:34 +00:00
|
|
|
KernelEvents::REQUEST,
|
|
|
|
KernelEvents::CONTROLLER,
|
|
|
|
KernelEvents::CONTROLLER_ARGUMENTS,
|
|
|
|
KernelEvents::RESPONSE,
|
|
|
|
KernelEvents::FINISH_REQUEST,
|
2019-01-16 09:39:14 +00:00
|
|
|
];
|
2017-11-08 09:48:34 +00:00
|
|
|
|
2019-06-27 17:12:00 +01:00
|
|
|
$this->addCompilerPassIfExists($container, ErrorCatcherPass::class);
|
2017-09-23 14:20:05 +01:00
|
|
|
$container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
|
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
|
2017-11-08 09:48:34 +00:00
|
|
|
$container->addCompilerPass((new RegisterListenersPass())->setHotPathEvents($hotPathEvents), PassConfig::TYPE_BEFORE_REMOVING);
|
2011-01-13 13:58:17 +00:00
|
|
|
$container->addCompilerPass(new TemplatingPass());
|
2019-02-06 10:00:25 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class);
|
2018-01-05 12:03:30 +00:00
|
|
|
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_AFTER_REMOVING, -255);
|
2017-02-22 23:37:05 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
|
2018-05-15 12:05:47 +01:00
|
|
|
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class, PassConfig::TYPE_BEFORE_REMOVING);
|
2018-11-07 11:59:44 +00:00
|
|
|
// must be registered as late as possible to get access to all Twig paths registered in
|
|
|
|
// twig.template_iterator definition
|
|
|
|
$this->addCompilerPassIfExists($container, TranslatorPass::class, PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
|
2019-02-08 17:17:48 +00:00
|
|
|
$this->addCompilerPassIfExists($container, TranslatorPathsPass::class, PassConfig::TYPE_AFTER_REMOVING);
|
2014-05-10 23:14:12 +01:00
|
|
|
$container->addCompilerPass(new LoggingTranslatorPass());
|
2018-06-15 09:48:05 +01:00
|
|
|
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
|
2017-05-05 11:35:04 +01:00
|
|
|
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
|
|
|
|
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
|
2017-09-05 16:39:41 +01:00
|
|
|
$container->addCompilerPass(new FragmentRendererPass());
|
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);
|
2016-09-10 10:05:01 +01:00
|
|
|
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2017-07-08 01:26:52 +01:00
|
|
|
$container->addCompilerPass(new CachePoolPrunerPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2017-01-13 19:57:15 +00:00
|
|
|
$this->addCompilerPassIfExists($container, FormPass::class);
|
2017-07-21 19:01:38 +01:00
|
|
|
$container->addCompilerPass(new WorkflowGuardListenerPass());
|
2017-09-11 15:29:04 +01:00
|
|
|
$container->addCompilerPass(new ResettableServicePass());
|
2018-10-10 23:18:00 +01:00
|
|
|
$container->addCompilerPass(new RegisterLocaleAwareServicesPass());
|
2018-03-12 19:13:33 +00:00
|
|
|
$container->addCompilerPass(new TestServiceContainerWeakRefPass(), PassConfig::TYPE_BEFORE_REMOVING, -32);
|
|
|
|
$container->addCompilerPass(new TestServiceContainerRealRefPass(), PassConfig::TYPE_AFTER_REMOVING);
|
2019-01-27 10:52:17 +00:00
|
|
|
$this->addCompilerPassIfExists($container, AddMimeTypeGuesserPass::class);
|
2017-09-30 13:16:30 +01:00
|
|
|
$this->addCompilerPassIfExists($container, MessengerPass::class);
|
2018-06-26 16:35:39 +01:00
|
|
|
$this->addCompilerPassIfExists($container, AddAutoMappingConfigurationPass::class);
|
2019-02-21 10:17:27 +00:00
|
|
|
$container->addCompilerPass(new RegisterReverseContainerPass(true));
|
|
|
|
$container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
|
2011-04-15 09:14:13 +01:00
|
|
|
|
|
|
|
if ($container->getParameter('kernel.debug')) {
|
2019-05-16 10:29:22 +01:00
|
|
|
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);
|
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-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
|
|
|
}
|