vendor/symfony/http-kernel/Kernel.php line 247

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel;
  11. use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
  12. use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
  13. use Symfony\Component\Config\ConfigCache;
  14. use Symfony\Component\Config\Loader\DelegatingLoader;
  15. use Symfony\Component\Config\Loader\LoaderResolver;
  16. use Symfony\Component\Debug\DebugClassLoader;
  17. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  18. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\DependencyInjection\ContainerInterface;
  21. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  22. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  23. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  24. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  25. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  26. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  27. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  28. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  29. use Symfony\Component\Filesystem\Filesystem;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  33. use Symfony\Component\HttpKernel\Config\FileLocator;
  34. use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
  35. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  36. /**
  37.  * The Kernel is the heart of the Symfony system.
  38.  *
  39.  * It manages an environment made of bundles.
  40.  *
  41.  * Environment names must always start with a letter and
  42.  * they must only contain letters and numbers.
  43.  *
  44.  * @author Fabien Potencier <fabien@symfony.com>
  45.  */
  46. abstract class Kernel implements KernelInterfaceRebootableInterfaceTerminableInterface
  47. {
  48.     /**
  49.      * @var BundleInterface[]
  50.      */
  51.     protected $bundles = [];
  52.     protected $container;
  53.     /**
  54.      * @deprecated since Symfony 4.2
  55.      */
  56.     protected $rootDir;
  57.     protected $environment;
  58.     protected $debug;
  59.     protected $booted false;
  60.     /**
  61.      * @deprecated since Symfony 4.2
  62.      */
  63.     protected $name;
  64.     protected $startTime;
  65.     private $projectDir;
  66.     private $warmupDir;
  67.     private $requestStackSize 0;
  68.     private $resetServices false;
  69.     const VERSION '4.3.4';
  70.     const VERSION_ID 40304;
  71.     const MAJOR_VERSION 4;
  72.     const MINOR_VERSION 3;
  73.     const RELEASE_VERSION 4;
  74.     const EXTRA_VERSION '';
  75.     const END_OF_MAINTENANCE '01/2020';
  76.     const END_OF_LIFE '07/2020';
  77.     public function __construct(string $environmentbool $debug)
  78.     {
  79.         /*
  80.         if(php_sapi_name() === 'cli' OR defined('STDIN')){ // Si on utilise l'appli hors du navigateur (ex : la console)
  81.             $server_name = 'qcentre2.extrakdo.com';
  82.         }else{
  83.            $server_name = $_SERVER['SERVER_NAME'];
  84.         }
  85.         
  86.         //echo 'vendor>s...>Kernel.php : __construct<br/>';
  87.         //die($_SERVER['SERVER_NAME']);
  88.         //$server_name = $_SERVER['SERVER_NAME'];
  89.         switch ($server_name) {
  90.             case 'qcentre2.extrakdo.com': // On se trouve sur le Centre
  91.             case '127.0.0.1:8000': // On se trouve sur le Centre
  92.                 $_SERVER['CONFIG_WEBSITE'] = array(
  93.                     'id' => '1',
  94.                     'folder' => 'centre',
  95.                     'name' => 'Nom du Centre',
  96.                     'slogan' => 'Slogan du Centre',
  97.                     'description' => 'Descr Centre',
  98.                     'keywords' => 'keywords Centre',
  99.                     'author' => 'Auteur Centre',
  100.                     'mail' => 'qcentre@extrakdo.com',
  101.                 );
  102.                 break;
  103.             case 'zzz': // On se trouve sur le site "1"
  104.                 $_SERVER['CONFIG_WEBSITE'] = array(
  105.                     'id' => '2',
  106.                     'folder' => 'site1',
  107.                     'name' => 'Nom du site 1',
  108.                     'slogan' => 'Slogan du site 1',
  109.                     'description' => 'Descr site 1',
  110.                     'keywords' => 'keywords site 1',
  111.                     'author' => 'Auteur site 1',
  112.                     'mail' => 'qcentre@extrakdo.com',
  113.                 );
  114.                 break;
  115.             default:
  116.                 die('Aucun site trouvĂ© !');
  117.         }
  118.                 
  119.         //session_destroy();
  120.         //echo '<pre>'; print_r($_SESSION['config']); echo '</pre>';
  121.         */
  122.         
  123.         
  124.         $this->environment $environment;
  125.         $this->debug $debug;
  126.         $this->rootDir $this->getRootDir(false);
  127.         $this->name $this->getName(false);
  128.     }
  129.     public function __clone()
  130.     {
  131.         $this->booted false;
  132.         $this->container null;
  133.         $this->requestStackSize 0;
  134.         $this->resetServices false;
  135.     }
  136.     /**
  137.      * {@inheritdoc}
  138.      */
  139.     public function boot()
  140.     {
  141.         if (true === $this->booted) {
  142.             if (!$this->requestStackSize && $this->resetServices) {
  143.                 if ($this->container->has('services_resetter')) {
  144.                     $this->container->get('services_resetter')->reset();
  145.                 }
  146.                 $this->resetServices false;
  147.                 if ($this->debug) {
  148.                     $this->startTime microtime(true);
  149.                 }
  150.             }
  151.             return;
  152.         }
  153.         if ($this->debug) {
  154.             $this->startTime microtime(true);
  155.         }
  156.         if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
  157.             putenv('SHELL_VERBOSITY=3');
  158.             $_ENV['SHELL_VERBOSITY'] = 3;
  159.             $_SERVER['SHELL_VERBOSITY'] = 3;
  160.         }
  161.         // init bundles
  162.         $this->initializeBundles();
  163.         // init container
  164.         $this->initializeContainer();
  165.         foreach ($this->getBundles() as $bundle) {
  166.             $bundle->setContainer($this->container);
  167.             $bundle->boot();
  168.         }
  169.         $this->booted true;
  170.     }
  171.     /**
  172.      * {@inheritdoc}
  173.      */
  174.     public function reboot($warmupDir)
  175.     {
  176.         $this->shutdown();
  177.         $this->warmupDir $warmupDir;
  178.         $this->boot();
  179.     }
  180.     /**
  181.      * {@inheritdoc}
  182.      */
  183.     public function terminate(Request $requestResponse $response)
  184.     {
  185.         if (false === $this->booted) {
  186.             return;
  187.         }
  188.         if ($this->getHttpKernel() instanceof TerminableInterface) {
  189.             $this->getHttpKernel()->terminate($request$response);
  190.         }
  191.     }
  192.     /**
  193.      * {@inheritdoc}
  194.      */
  195.     public function shutdown()
  196.     {
  197.         if (false === $this->booted) {
  198.             return;
  199.         }
  200.         $this->booted false;
  201.         foreach ($this->getBundles() as $bundle) {
  202.             $bundle->shutdown();
  203.             $bundle->setContainer(null);
  204.         }
  205.         $this->container null;
  206.         $this->requestStackSize 0;
  207.         $this->resetServices false;
  208.     }
  209.     /**
  210.      * {@inheritdoc}
  211.      */
  212.     public function handle(Request $request$type HttpKernelInterface::MASTER_REQUEST$catch true)
  213.     {
  214.         $this->boot();
  215.         ++$this->requestStackSize;
  216.         $this->resetServices true;
  217.         try {
  218.             return $this->getHttpKernel()->handle($request$type$catch);
  219.         } finally {
  220.             --$this->requestStackSize;
  221.         }
  222.     }
  223.     /**
  224.      * Gets a HTTP kernel from the container.
  225.      *
  226.      * @return HttpKernelInterface
  227.      */
  228.     protected function getHttpKernel()
  229.     {
  230.         return $this->container->get('http_kernel');
  231.     }
  232.     /**
  233.      * {@inheritdoc}
  234.      */
  235.     public function getBundles()
  236.     {
  237.         return $this->bundles;
  238.     }
  239.     /**
  240.      * {@inheritdoc}
  241.      */
  242.     public function getBundle($name)
  243.     {
  244.         if (!isset($this->bundles[$name])) {
  245.             $class = \get_class($this);
  246.             $class 'c' === $class[0] && === strpos($class"class@anonymous\0") ? get_parent_class($class).'@anonymous' $class;
  247.             throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your %s.php file?'$name$class));
  248.         }
  249.         return $this->bundles[$name];
  250.     }
  251.     /**
  252.      * {@inheritdoc}
  253.      *
  254.      * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
  255.      */
  256.     public function locateResource($name$dir null$first true)
  257.     {
  258.         if ('@' !== $name[0]) {
  259.             throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).'$name));
  260.         }
  261.         if (false !== strpos($name'..')) {
  262.             throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).'$name));
  263.         }
  264.         $bundleName substr($name1);
  265.         $path '';
  266.         if (false !== strpos($bundleName'/')) {
  267.             list($bundleName$path) = explode('/'$bundleName2);
  268.         }
  269.         $isResource === strpos($path'Resources') && null !== $dir;
  270.         $overridePath substr($path9);
  271.         $bundle $this->getBundle($bundleName);
  272.         $files = [];
  273.         if ($isResource && file_exists($file $dir.'/'.$bundle->getName().$overridePath)) {
  274.             $files[] = $file;
  275.         }
  276.         if (file_exists($file $bundle->getPath().'/'.$path)) {
  277.             if ($first && !$isResource) {
  278.                 return $file;
  279.             }
  280.             $files[] = $file;
  281.         }
  282.         if (\count($files) > 0) {
  283.             return $first && $isResource $files[0] : $files;
  284.         }
  285.         throw new \InvalidArgumentException(sprintf('Unable to find file "%s".'$name));
  286.     }
  287.     /**
  288.      * {@inheritdoc}
  289.      *
  290.      * @deprecated since Symfony 4.2
  291.      */
  292.     public function getName(/* $triggerDeprecation = true */)
  293.     {
  294.         if (=== \func_num_args() || func_get_arg(0)) {
  295.             @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.'__METHOD__), E_USER_DEPRECATED);
  296.         }
  297.         if (null === $this->name) {
  298.             $this->name preg_replace('/[^a-zA-Z0-9_]+/'''basename($this->rootDir));
  299.             if (ctype_digit($this->name[0])) {
  300.                 $this->name '_'.$this->name;
  301.             }
  302.         }
  303.         return $this->name;
  304.     }
  305.     /**
  306.      * {@inheritdoc}
  307.      */
  308.     public function getEnvironment()
  309.     {
  310.         return $this->environment;
  311.     }
  312.     /**
  313.      * {@inheritdoc}
  314.      */
  315.     public function isDebug()
  316.     {
  317.         return $this->debug;
  318.     }
  319.     /**
  320.      * {@inheritdoc}
  321.      *
  322.      * @deprecated since Symfony 4.2, use getProjectDir() instead
  323.      */
  324.     public function getRootDir(/* $triggerDeprecation = true */)
  325.     {
  326.         if (=== \func_num_args() || func_get_arg(0)) {
  327.             @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use getProjectDir() instead.'__METHOD__), E_USER_DEPRECATED);
  328.         }
  329.         if (null === $this->rootDir) {
  330.             $r = new \ReflectionObject($this);
  331.             $this->rootDir = \dirname($r->getFileName());
  332.         }
  333.         return $this->rootDir;
  334.     }
  335.     /**
  336.      * Gets the application root dir (path of the project's composer file).
  337.      *
  338.      * @return string The project root dir
  339.      */
  340.     public function getProjectDir()
  341.     {
  342.         if (null === $this->projectDir) {
  343.             $r = new \ReflectionObject($this);
  344.             $dir $rootDir = \dirname($r->getFileName());
  345.             while (!file_exists($dir.'/composer.json')) {
  346.                 if ($dir === \dirname($dir)) {
  347.                     return $this->projectDir $rootDir;
  348.                 }
  349.                 $dir = \dirname($dir);
  350.             }
  351.             $this->projectDir $dir;
  352.         }
  353.         return $this->projectDir;
  354.     }
  355.     /**
  356.      * {@inheritdoc}
  357.      */
  358.     public function getContainer()
  359.     {
  360.         return $this->container;
  361.     }
  362.     /**
  363.      * @internal
  364.      */
  365.     public function setAnnotatedClassCache(array $annotatedClasses)
  366.     {
  367.         file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/annotations.map'sprintf('<?php return %s;'var_export($annotatedClassestrue)));
  368.     }
  369.     /**
  370.      * {@inheritdoc}
  371.      */
  372.     public function getStartTime()
  373.     {
  374.         return $this->debug && null !== $this->startTime $this->startTime : -INF;
  375.     }
  376.     /**
  377.      * {@inheritdoc}
  378.      */
  379.     public function getCacheDir()
  380.     {
  381.         return $this->getProjectDir().'/var/cache/'.$this->environment;
  382.     }
  383.     /**
  384.      * {@inheritdoc}
  385.      */
  386.     public function getLogDir()
  387.     {
  388.         return $this->getProjectDir().'/var/log';
  389.     }
  390.     /**
  391.      * {@inheritdoc}
  392.      */
  393.     public function getCharset()
  394.     {
  395.         return 'UTF-8';
  396.     }
  397.     /**
  398.      * Gets the patterns defining the classes to parse and cache for annotations.
  399.      */
  400.     public function getAnnotatedClassesToCompile(): array
  401.     {
  402.         return [];
  403.     }
  404.     /**
  405.      * Initializes bundles.
  406.      *
  407.      * @throws \LogicException if two bundles share a common name
  408.      */
  409.     protected function initializeBundles()
  410.     {
  411.         // init bundles
  412.         $this->bundles = [];
  413.         foreach ($this->registerBundles() as $bundle) {
  414.             $name $bundle->getName();
  415.             if (isset($this->bundles[$name])) {
  416.                 throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"'$name));
  417.             }
  418.             $this->bundles[$name] = $bundle;
  419.         }
  420.     }
  421.     /**
  422.      * The extension point similar to the Bundle::build() method.
  423.      *
  424.      * Use this method to register compiler passes and manipulate the container during the building process.
  425.      */
  426.     protected function build(ContainerBuilder $container)
  427.     {
  428.     }
  429.     /**
  430.      * Gets the container class.
  431.      *
  432.      * @throws \InvalidArgumentException If the generated classname is invalid
  433.      *
  434.      * @return string The container class
  435.      */
  436.     protected function getContainerClass()
  437.     {
  438.         $class = \get_class($this);
  439.         $class 'c' === $class[0] && === strpos($class"class@anonymous\0") ? get_parent_class($class).str_replace('.''_'ContainerBuilder::hash($class)) : $class;
  440.         $class $this->name.str_replace('\\''_'$class).ucfirst($this->environment).($this->debug 'Debug' '').'Container';
  441.         if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/'$class)) {
  442.             throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.'$this->environment));
  443.         }
  444.         return $class;
  445.     }
  446.     /**
  447.      * Gets the container's base class.
  448.      *
  449.      * All names except Container must be fully qualified.
  450.      *
  451.      * @return string
  452.      */
  453.     protected function getContainerBaseClass()
  454.     {
  455.         return 'Container';
  456.     }
  457.     /**
  458.      * Initializes the service container.
  459.      *
  460.      * The cached version of the service container is used when fresh, otherwise the
  461.      * container is built.
  462.      */
  463.     protected function initializeContainer()
  464.     {
  465.         $class $this->getContainerClass();
  466.         $cacheDir $this->warmupDir ?: $this->getCacheDir();
  467.         $cache = new ConfigCache($cacheDir.'/'.$class.'.php'$this->debug);
  468.         $oldContainer null;
  469.         if ($fresh $cache->isFresh()) {
  470.             // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
  471.             $errorLevel error_reporting(\E_ALL ^ \E_WARNING);
  472.             $fresh $oldContainer false;
  473.             try {
  474.                 if (file_exists($cache->getPath()) && \is_object($this->container = include $cache->getPath())) {
  475.                     $this->container->set('kernel'$this);
  476.                     $oldContainer $this->container;
  477.                     $fresh true;
  478.                 }
  479.             } catch (\Throwable $e) {
  480.             } finally {
  481.                 error_reporting($errorLevel);
  482.             }
  483.         }
  484.         if ($fresh) {
  485.             return;
  486.         }
  487.         if ($collectDeprecations $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
  488.             $collectedLogs = [];
  489.             $previousHandler set_error_handler(function ($type$message$file$line) use (&$collectedLogs, &$previousHandler) {
  490.                 if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
  491.                     return $previousHandler $previousHandler($type$message$file$line) : false;
  492.                 }
  493.                 if (isset($collectedLogs[$message])) {
  494.                     ++$collectedLogs[$message]['count'];
  495.                     return null;
  496.                 }
  497.                 $backtrace debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS5);
  498.                 // Clean the trace by removing first frames added by the error handler itself.
  499.                 for ($i 0; isset($backtrace[$i]); ++$i) {
  500.                     if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
  501.                         $backtrace = \array_slice($backtrace$i);
  502.                         break;
  503.                     }
  504.                 }
  505.                 // Remove frames added by DebugClassLoader.
  506.                 for ($i = \count($backtrace) - 2$i; --$i) {
  507.                     if (DebugClassLoader::class === ($backtrace[$i]['class'] ?? null)) {
  508.                         $backtrace = [$backtrace[$i 1]];
  509.                         break;
  510.                     }
  511.                 }
  512.                 $collectedLogs[$message] = [
  513.                     'type' => $type,
  514.                     'message' => $message,
  515.                     'file' => $file,
  516.                     'line' => $line,
  517.                     'trace' => [$backtrace[0]],
  518.                     'count' => 1,
  519.                 ];
  520.                 return null;
  521.             });
  522.         }
  523.         try {
  524.             $container null;
  525.             $container $this->buildContainer();
  526.             $container->compile();
  527.         } finally {
  528.             if ($collectDeprecations) {
  529.                 restore_error_handler();
  530.                 file_put_contents($cacheDir.'/'.$class.'Deprecations.log'serialize(array_values($collectedLogs)));
  531.                 file_put_contents($cacheDir.'/'.$class.'Compiler.log'null !== $container implode("\n"$container->getCompiler()->getLog()) : '');
  532.             }
  533.         }
  534.         if (null === $oldContainer && file_exists($cache->getPath())) {
  535.             $errorLevel error_reporting(\E_ALL ^ \E_WARNING);
  536.             try {
  537.                 $oldContainer = include $cache->getPath();
  538.             } catch (\Throwable $e) {
  539.             } finally {
  540.                 error_reporting($errorLevel);
  541.             }
  542.         }
  543.         $oldContainer = \is_object($oldContainer) ? new \ReflectionClass($oldContainer) : false;
  544.         $this->dumpContainer($cache$container$class$this->getContainerBaseClass());
  545.         $this->container = require $cache->getPath();
  546.         $this->container->set('kernel'$this);
  547.         if ($oldContainer && \get_class($this->container) !== $oldContainer->name) {
  548.             // Because concurrent requests might still be using them,
  549.             // old container files are not removed immediately,
  550.             // but on a next dump of the container.
  551.             static $legacyContainers = [];
  552.             $oldContainerDir = \dirname($oldContainer->getFileName());
  553.             $legacyContainers[$oldContainerDir.'.legacy'] = true;
  554.             foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy') as $legacyContainer) {
  555.                 if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
  556.                     (new Filesystem())->remove(substr($legacyContainer0, -7));
  557.                 }
  558.             }
  559.             touch($oldContainerDir.'.legacy');
  560.         }
  561.         if ($this->container->has('cache_warmer')) {
  562.             $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  563.         }
  564.     }
  565.     /**
  566.      * Returns the kernel parameters.
  567.      *
  568.      * @return array An array of kernel parameters
  569.      */
  570.     protected function getKernelParameters()
  571.     {
  572.         $bundles = [];
  573.         $bundlesMetadata = [];
  574.         foreach ($this->bundles as $name => $bundle) {
  575.             $bundles[$name] = \get_class($bundle);
  576.             $bundlesMetadata[$name] = [
  577.                 'path' => $bundle->getPath(),
  578.                 'namespace' => $bundle->getNamespace(),
  579.             ];
  580.         }
  581.         return [
  582.             /*
  583.              * @deprecated since Symfony 4.2, use kernel.project_dir instead
  584.              */
  585.             'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
  586.             'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
  587.             'kernel.environment' => $this->environment,
  588.             'kernel.debug' => $this->debug,
  589.             /*
  590.              * @deprecated since Symfony 4.2
  591.              */
  592.             'kernel.name' => $this->name,
  593.             'kernel.cache_dir' => realpath($cacheDir $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
  594.             'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
  595.             'kernel.bundles' => $bundles,
  596.             'kernel.bundles_metadata' => $bundlesMetadata,
  597.             'kernel.charset' => $this->getCharset(),
  598.             'kernel.container_class' => $this->getContainerClass(),
  599.         ];
  600.     }
  601.     /**
  602.      * Builds the service container.
  603.      *
  604.      * @return ContainerBuilder The compiled service container
  605.      *
  606.      * @throws \RuntimeException
  607.      */
  608.     protected function buildContainer()
  609.     {
  610.         foreach (['cache' => $this->warmupDir ?: $this->getCacheDir(), 'logs' => $this->getLogDir()] as $name => $dir) {
  611.             if (!is_dir($dir)) {
  612.                 if (false === @mkdir($dir0777true) && !is_dir($dir)) {
  613.                     throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n"$name$dir));
  614.                 }
  615.             } elseif (!is_writable($dir)) {
  616.                 throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n"$name$dir));
  617.             }
  618.         }
  619.         $container $this->getContainerBuilder();
  620.         $container->addObjectResource($this);
  621.         $this->prepareContainer($container);
  622.         if (null !== $cont $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  623.             $container->merge($cont);
  624.         }
  625.         $container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
  626.         return $container;
  627.     }
  628.     /**
  629.      * Prepares the ContainerBuilder before it is compiled.
  630.      */
  631.     protected function prepareContainer(ContainerBuilder $container)
  632.     {
  633.         $extensions = [];
  634.         foreach ($this->bundles as $bundle) {
  635.             if ($extension $bundle->getContainerExtension()) {
  636.                 $container->registerExtension($extension);
  637.             }
  638.             if ($this->debug) {
  639.                 $container->addObjectResource($bundle);
  640.             }
  641.         }
  642.         foreach ($this->bundles as $bundle) {
  643.             $bundle->build($container);
  644.         }
  645.         $this->build($container);
  646.         foreach ($container->getExtensions() as $extension) {
  647.             $extensions[] = $extension->getAlias();
  648.         }
  649.         // ensure these extensions are implicitly loaded
  650.         $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  651.     }
  652.     /**
  653.      * Gets a new ContainerBuilder instance used to build the service container.
  654.      *
  655.      * @return ContainerBuilder
  656.      */
  657.     protected function getContainerBuilder()
  658.     {
  659.         $container = new ContainerBuilder();
  660.         $container->getParameterBag()->add($this->getKernelParameters());
  661.         if ($this instanceof CompilerPassInterface) {
  662.             $container->addCompilerPass($thisPassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
  663.         }
  664.         if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
  665.             $container->setProxyInstantiator(new RuntimeInstantiator());
  666.         }
  667.         return $container;
  668.     }
  669.     /**
  670.      * Dumps the service container to PHP code in the cache.
  671.      *
  672.      * @param ConfigCache      $cache     The config cache
  673.      * @param ContainerBuilder $container The service container
  674.      * @param string           $class     The name of the class to generate
  675.      * @param string           $baseClass The name of the container's base class
  676.      */
  677.     protected function dumpContainer(ConfigCache $cacheContainerBuilder $container$class$baseClass)
  678.     {
  679.         // cache the container
  680.         $dumper = new PhpDumper($container);
  681.         if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
  682.             $dumper->setProxyDumper(new ProxyDumper());
  683.         }
  684.         $content $dumper->dump([
  685.             'class' => $class,
  686.             'base_class' => $baseClass,
  687.             'file' => $cache->getPath(),
  688.             'as_files' => true,
  689.             'debug' => $this->debug,
  690.             'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
  691.         ]);
  692.         $rootCode array_pop($content);
  693.         $dir = \dirname($cache->getPath()).'/';
  694.         $fs = new Filesystem();
  695.         foreach ($content as $file => $code) {
  696.             $fs->dumpFile($dir.$file$code);
  697.             @chmod($dir.$file0666 & ~umask());
  698.         }
  699.         $legacyFile = \dirname($dir.$file).'.legacy';
  700.         if (file_exists($legacyFile)) {
  701.             @unlink($legacyFile);
  702.         }
  703.         $cache->write($rootCode$container->getResources());
  704.     }
  705.     /**
  706.      * Returns a loader for the container.
  707.      *
  708.      * @return DelegatingLoader The loader
  709.      */
  710.     protected function getContainerLoader(ContainerInterface $container)
  711.     {
  712.         $locator = new FileLocator($this);
  713.         $resolver = new LoaderResolver([
  714.             new XmlFileLoader($container$locator),
  715.             new YamlFileLoader($container$locator),
  716.             new IniFileLoader($container$locator),
  717.             new PhpFileLoader($container$locator),
  718.             new GlobFileLoader($container$locator),
  719.             new DirectoryLoader($container$locator),
  720.             new ClosureLoader($container),
  721.         ]);
  722.         return new DelegatingLoader($resolver);
  723.     }
  724.     /**
  725.      * Removes comments from a PHP source string.
  726.      *
  727.      * We don't use the PHP php_strip_whitespace() function
  728.      * as we want the content to be readable and well-formatted.
  729.      *
  730.      * @param string $source A PHP string
  731.      *
  732.      * @return string The PHP string with the comments removed
  733.      */
  734.     public static function stripComments($source)
  735.     {
  736.         if (!\function_exists('token_get_all')) {
  737.             return $source;
  738.         }
  739.         $rawChunk '';
  740.         $output '';
  741.         $tokens token_get_all($source);
  742.         $ignoreSpace false;
  743.         for ($i 0; isset($tokens[$i]); ++$i) {
  744.             $token $tokens[$i];
  745.             if (!isset($token[1]) || 'b"' === $token) {
  746.                 $rawChunk .= $token;
  747.             } elseif (T_START_HEREDOC === $token[0]) {
  748.                 $output .= $rawChunk.$token[1];
  749.                 do {
  750.                     $token $tokens[++$i];
  751.                     $output .= isset($token[1]) && 'b"' !== $token $token[1] : $token;
  752.                 } while (T_END_HEREDOC !== $token[0]);
  753.                 $rawChunk '';
  754.             } elseif (T_WHITESPACE === $token[0]) {
  755.                 if ($ignoreSpace) {
  756.                     $ignoreSpace false;
  757.                     continue;
  758.                 }
  759.                 // replace multiple new lines with a single newline
  760.                 $rawChunk .= preg_replace(['/\n{2,}/S'], "\n"$token[1]);
  761.             } elseif (\in_array($token[0], [T_COMMENTT_DOC_COMMENT])) {
  762.                 $ignoreSpace true;
  763.             } else {
  764.                 $rawChunk .= $token[1];
  765.                 // The PHP-open tag already has a new-line
  766.                 if (T_OPEN_TAG === $token[0]) {
  767.                     $ignoreSpace true;
  768.                 }
  769.             }
  770.         }
  771.         $output .= $rawChunk;
  772.         unset($tokens$rawChunk);
  773.         gc_mem_caches();
  774.         return $output;
  775.     }
  776.     /**
  777.      * @deprecated since Symfony 4.3
  778.      */
  779.     public function serialize()
  780.     {
  781.         @trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.'__METHOD__), E_USER_DEPRECATED);
  782.         return serialize([$this->environment$this->debug]);
  783.     }
  784.     /**
  785.      * @deprecated since Symfony 4.3
  786.      */
  787.     public function unserialize($data)
  788.     {
  789.         @trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.'__METHOD__), E_USER_DEPRECATED);
  790.         list($environment$debug) = unserialize($data, ['allowed_classes' => false]);
  791.         $this->__construct($environment$debug);
  792.     }
  793.     public function __sleep()
  794.     {
  795.         if (__CLASS__ !== $c = (new \ReflectionMethod($this'serialize'))->getDeclaringClass()->name) {
  796.             @trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.'$c), E_USER_DEPRECATED);
  797.             $this->serialized $this->serialize();
  798.             return ['serialized'];
  799.         }
  800.         return ['environment''debug'];
  801.     }
  802.     public function __wakeup()
  803.     {
  804.         if (__CLASS__ !== $c = (new \ReflectionMethod($this'serialize'))->getDeclaringClass()->name) {
  805.             @trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.'$c), E_USER_DEPRECATED);
  806.             $this->unserialize($this->serialized);
  807.             unset($this->serialized);
  808.             return;
  809.         }
  810.         $this->__construct($this->environment$this->debug);
  811.     }
  812. }