vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 168

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\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  16. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  17. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  18. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  19. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  20. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  21. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  25. use Symfony\Component\HttpKernel\Config\EnvParametersResource;
  26. use Symfony\Component\HttpKernel\Config\FileLocator;
  27. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  28. use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
  29. use Symfony\Component\Config\Loader\LoaderResolver;
  30. use Symfony\Component\Config\Loader\DelegatingLoader;
  31. use Symfony\Component\Config\ConfigCache;
  32. use Symfony\Component\ClassLoader\ClassCollectionLoader;
  33. /**
  34.  * The Kernel is the heart of the Symfony system.
  35.  *
  36.  * It manages an environment made of bundles.
  37.  *
  38.  * @author Fabien Potencier <fabien@symfony.com>
  39.  */
  40. abstract class Kernel implements KernelInterfaceTerminableInterface
  41. {
  42.     /**
  43.      * @var BundleInterface[]
  44.      */
  45.     protected $bundles = array();
  46.     protected $bundleMap;
  47.     protected $container;
  48.     protected $rootDir;
  49.     protected $environment;
  50.     protected $debug;
  51.     protected $booted false;
  52.     protected $name;
  53.     protected $startTime;
  54.     protected $loadClassCache;
  55.     const VERSION '3.2.13';
  56.     const VERSION_ID 30213;
  57.     const MAJOR_VERSION 3;
  58.     const MINOR_VERSION 2;
  59.     const RELEASE_VERSION 13;
  60.     const EXTRA_VERSION '';
  61.     const END_OF_MAINTENANCE '07/2017';
  62.     const END_OF_LIFE '01/2018';
  63.     /**
  64.      * Constructor.
  65.      *
  66.      * @param string $environment The environment
  67.      * @param bool   $debug       Whether to enable debugging or not
  68.      */
  69.     public function __construct($environment$debug)
  70.     {
  71.         $this->environment $environment;
  72.         $this->debug = (bool) $debug;
  73.         $this->rootDir $this->getRootDir();
  74.         $this->name $this->getName();
  75.         if ($this->debug) {
  76.             $this->startTime microtime(true);
  77.         }
  78.     }
  79.     public function __clone()
  80.     {
  81.         if ($this->debug) {
  82.             $this->startTime microtime(true);
  83.         }
  84.         $this->booted false;
  85.         $this->container null;
  86.     }
  87.     /**
  88.      * Boots the current kernel.
  89.      */
  90.     public function boot()
  91.     {
  92.         if (true === $this->booted) {
  93.             return;
  94.         }
  95.         if ($this->loadClassCache) {
  96.             $this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
  97.         }
  98.         // init bundles
  99.         $this->initializeBundles();
  100.         // init container
  101.         $this->initializeContainer();
  102.         foreach ($this->getBundles() as $bundle) {
  103.             $bundle->setContainer($this->container);
  104.             $bundle->boot();
  105.         }
  106.         $this->booted true;
  107.     }
  108.     /**
  109.      * {@inheritdoc}
  110.      */
  111.     public function terminate(Request $requestResponse $response)
  112.     {
  113.         if (false === $this->booted) {
  114.             return;
  115.         }
  116.         if ($this->getHttpKernel() instanceof TerminableInterface) {
  117.             $this->getHttpKernel()->terminate($request$response);
  118.         }
  119.     }
  120.     /**
  121.      * {@inheritdoc}
  122.      */
  123.     public function shutdown()
  124.     {
  125.         if (false === $this->booted) {
  126.             return;
  127.         }
  128.         $this->booted false;
  129.         foreach ($this->getBundles() as $bundle) {
  130.             $bundle->shutdown();
  131.             $bundle->setContainer(null);
  132.         }
  133.         $this->container null;
  134.     }
  135.     /**
  136.      * {@inheritdoc}
  137.      */
  138.     public function handle(Request $request$type HttpKernelInterface::MASTER_REQUEST$catch true)
  139.     {
  140.         if (false === $this->booted) {
  141.             $this->boot();
  142.         }
  143.         return $this->getHttpKernel()->handle($request$type$catch);
  144.     }
  145.     /**
  146.      * Gets a HTTP kernel from the container.
  147.      *
  148.      * @return HttpKernel
  149.      */
  150.     protected function getHttpKernel()
  151.     {
  152.         return $this->container->get('http_kernel');
  153.     }
  154.     /**
  155.      * {@inheritdoc}
  156.      */
  157.     public function getBundles()
  158.     {
  159.         return $this->bundles;
  160.     }
  161.     /**
  162.      * {@inheritdoc}
  163.      */
  164.     public function getBundle($name$first true)
  165.     {
  166.         if (!isset($this->bundleMap[$name])) {
  167.             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?'$nameget_class($this)));
  168.         }
  169.         if (true === $first) {
  170.             return $this->bundleMap[$name][0];
  171.         }
  172.         return $this->bundleMap[$name];
  173.     }
  174.     /**
  175.      * {@inheritdoc}
  176.      *
  177.      * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle
  178.      */
  179.     public function locateResource($name$dir null$first true)
  180.     {
  181.         if ('@' !== $name[0]) {
  182.             throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).'$name));
  183.         }
  184.         if (false !== strpos($name'..')) {
  185.             throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).'$name));
  186.         }
  187.         $bundleName substr($name1);
  188.         $path '';
  189.         if (false !== strpos($bundleName'/')) {
  190.             list($bundleName$path) = explode('/'$bundleName2);
  191.         }
  192.         $isResource === strpos($path'Resources') && null !== $dir;
  193.         $overridePath substr($path9);
  194.         $resourceBundle null;
  195.         $bundles $this->getBundle($bundleNamefalse);
  196.         $files = array();
  197.         foreach ($bundles as $bundle) {
  198.             if ($isResource && file_exists($file $dir.'/'.$bundle->getName().$overridePath)) {
  199.                 if (null !== $resourceBundle) {
  200.                     throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
  201.                         $file,
  202.                         $resourceBundle,
  203.                         $dir.'/'.$bundles[0]->getName().$overridePath
  204.                     ));
  205.                 }
  206.                 if ($first) {
  207.                     return $file;
  208.                 }
  209.                 $files[] = $file;
  210.             }
  211.             if (file_exists($file $bundle->getPath().'/'.$path)) {
  212.                 if ($first && !$isResource) {
  213.                     return $file;
  214.                 }
  215.                 $files[] = $file;
  216.                 $resourceBundle $bundle->getName();
  217.             }
  218.         }
  219.         if (count($files) > 0) {
  220.             return $first && $isResource $files[0] : $files;
  221.         }
  222.         throw new \InvalidArgumentException(sprintf('Unable to find file "%s".'$name));
  223.     }
  224.     /**
  225.      * {@inheritdoc}
  226.      */
  227.     public function getName()
  228.     {
  229.         if (null === $this->name) {
  230.             $this->name preg_replace('/[^a-zA-Z0-9_]+/'''basename($this->rootDir));
  231.             if (ctype_digit($this->name[0])) {
  232.                 $this->name '_'.$this->name;
  233.             }
  234.         }
  235.         return $this->name;
  236.     }
  237.     /**
  238.      * {@inheritdoc}
  239.      */
  240.     public function getEnvironment()
  241.     {
  242.         return $this->environment;
  243.     }
  244.     /**
  245.      * {@inheritdoc}
  246.      */
  247.     public function isDebug()
  248.     {
  249.         return $this->debug;
  250.     }
  251.     /**
  252.      * {@inheritdoc}
  253.      */
  254.     public function getRootDir()
  255.     {
  256.         if (null === $this->rootDir) {
  257.             $r = new \ReflectionObject($this);
  258.             $this->rootDir dirname($r->getFileName());
  259.         }
  260.         return $this->rootDir;
  261.     }
  262.     /**
  263.      * {@inheritdoc}
  264.      */
  265.     public function getContainer()
  266.     {
  267.         return $this->container;
  268.     }
  269.     /**
  270.      * Loads the PHP class cache.
  271.      *
  272.      * This methods only registers the fact that you want to load the cache classes.
  273.      * The cache will actually only be loaded when the Kernel is booted.
  274.      *
  275.      * That optimization is mainly useful when using the HttpCache class in which
  276.      * case the class cache is not loaded if the Response is in the cache.
  277.      *
  278.      * @param string $name      The cache name prefix
  279.      * @param string $extension File extension of the resulting file
  280.      */
  281.     public function loadClassCache($name 'classes'$extension '.php')
  282.     {
  283.         $this->loadClassCache = array($name$extension);
  284.     }
  285.     /**
  286.      * @internal
  287.      */
  288.     public function setClassCache(array $classes)
  289.     {
  290.         file_put_contents($this->getCacheDir().'/classes.map'sprintf('<?php return %s;'var_export($classestrue)));
  291.     }
  292.     /**
  293.      * @internal
  294.      */
  295.     public function setAnnotatedClassCache(array $annotatedClasses)
  296.     {
  297.         file_put_contents($this->getCacheDir().'/annotations.map'sprintf('<?php return %s;'var_export($annotatedClassestrue)));
  298.     }
  299.     /**
  300.      * {@inheritdoc}
  301.      */
  302.     public function getStartTime()
  303.     {
  304.         return $this->debug $this->startTime : -INF;
  305.     }
  306.     /**
  307.      * {@inheritdoc}
  308.      */
  309.     public function getCacheDir()
  310.     {
  311.         return $this->rootDir.'/cache/'.$this->environment;
  312.     }
  313.     /**
  314.      * {@inheritdoc}
  315.      */
  316.     public function getLogDir()
  317.     {
  318.         return $this->rootDir.'/logs';
  319.     }
  320.     /**
  321.      * {@inheritdoc}
  322.      */
  323.     public function getCharset()
  324.     {
  325.         return 'UTF-8';
  326.     }
  327.     protected function doLoadClassCache($name$extension)
  328.     {
  329.         if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
  330.             ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name$this->debugfalse$extension);
  331.         }
  332.     }
  333.     /**
  334.      * Initializes the data structures related to the bundle management.
  335.      *
  336.      *  - the bundles property maps a bundle name to the bundle instance,
  337.      *  - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).
  338.      *
  339.      * @throws \LogicException if two bundles share a common name
  340.      * @throws \LogicException if a bundle tries to extend a non-registered bundle
  341.      * @throws \LogicException if a bundle tries to extend itself
  342.      * @throws \LogicException if two bundles extend the same ancestor
  343.      */
  344.     protected function initializeBundles()
  345.     {
  346.         // init bundles
  347.         $this->bundles = array();
  348.         $topMostBundles = array();
  349.         $directChildren = array();
  350.         foreach ($this->registerBundles() as $bundle) {
  351.             $name $bundle->getName();
  352.             if (isset($this->bundles[$name])) {
  353.                 throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"'$name));
  354.             }
  355.             $this->bundles[$name] = $bundle;
  356.             if ($parentName $bundle->getParent()) {
  357.                 if (isset($directChildren[$parentName])) {
  358.                     throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".'$parentName$name$directChildren[$parentName]));
  359.                 }
  360.                 if ($parentName == $name) {
  361.                     throw new \LogicException(sprintf('Bundle "%s" can not extend itself.'$name));
  362.                 }
  363.                 $directChildren[$parentName] = $name;
  364.             } else {
  365.                 $topMostBundles[$name] = $bundle;
  366.             }
  367.         }
  368.         // look for orphans
  369.         if (!empty($directChildren) && count($diff array_diff_key($directChildren$this->bundles))) {
  370.             $diff array_keys($diff);
  371.             throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.'$directChildren[$diff[0]], $diff[0]));
  372.         }
  373.         // inheritance
  374.         $this->bundleMap = array();
  375.         foreach ($topMostBundles as $name => $bundle) {
  376.             $bundleMap = array($bundle);
  377.             $hierarchy = array($name);
  378.             while (isset($directChildren[$name])) {
  379.                 $name $directChildren[$name];
  380.                 array_unshift($bundleMap$this->bundles[$name]);
  381.                 $hierarchy[] = $name;
  382.             }
  383.             foreach ($hierarchy as $hierarchyBundle) {
  384.                 $this->bundleMap[$hierarchyBundle] = $bundleMap;
  385.                 array_pop($bundleMap);
  386.             }
  387.         }
  388.     }
  389.     /**
  390.      * Gets the container class.
  391.      *
  392.      * @return string The container class
  393.      */
  394.     protected function getContainerClass()
  395.     {
  396.         return $this->name.ucfirst($this->environment).($this->debug 'Debug' '').'ProjectContainer';
  397.     }
  398.     /**
  399.      * Gets the container's base class.
  400.      *
  401.      * All names except Container must be fully qualified.
  402.      *
  403.      * @return string
  404.      */
  405.     protected function getContainerBaseClass()
  406.     {
  407.         return 'Container';
  408.     }
  409.     /**
  410.      * Initializes the service container.
  411.      *
  412.      * The cached version of the service container is used when fresh, otherwise the
  413.      * container is built.
  414.      */
  415.     protected function initializeContainer()
  416.     {
  417.         $class $this->getContainerClass();
  418.         $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php'$this->debug);
  419.         $fresh true;
  420.         if (!$cache->isFresh()) {
  421.             $container $this->buildContainer();
  422.             $container->compile();
  423.             $this->dumpContainer($cache$container$class$this->getContainerBaseClass());
  424.             $fresh false;
  425.         }
  426.         require_once $cache->getPath();
  427.         $this->container = new $class();
  428.         $this->container->set('kernel'$this);
  429.         if (!$fresh && $this->container->has('cache_warmer')) {
  430.             $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
  431.         }
  432.     }
  433.     /**
  434.      * Returns the kernel parameters.
  435.      *
  436.      * @return array An array of kernel parameters
  437.      */
  438.     protected function getKernelParameters()
  439.     {
  440.         $bundles = array();
  441.         $bundlesMetadata = array();
  442.         foreach ($this->bundles as $name => $bundle) {
  443.             $bundles[$name] = get_class($bundle);
  444.             $bundlesMetadata[$name] = array(
  445.                 'parent' => $bundle->getParent(),
  446.                 'path' => $bundle->getPath(),
  447.                 'namespace' => $bundle->getNamespace(),
  448.             );
  449.         }
  450.         return array_merge(
  451.             array(
  452.                 'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
  453.                 'kernel.environment' => $this->environment,
  454.                 'kernel.debug' => $this->debug,
  455.                 'kernel.name' => $this->name,
  456.                 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
  457.                 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
  458.                 'kernel.bundles' => $bundles,
  459.                 'kernel.bundles_metadata' => $bundlesMetadata,
  460.                 'kernel.charset' => $this->getCharset(),
  461.                 'kernel.container_class' => $this->getContainerClass(),
  462.             ),
  463.             $this->getEnvParameters()
  464.         );
  465.     }
  466.     /**
  467.      * Gets the environment parameters.
  468.      *
  469.      * Only the parameters starting with "SYMFONY__" are considered.
  470.      *
  471.      * @return array An array of parameters
  472.      */
  473.     protected function getEnvParameters()
  474.     {
  475.         $parameters = array();
  476.         foreach ($_SERVER as $key => $value) {
  477.             if (=== strpos($key'SYMFONY__')) {
  478.                 $parameters[strtolower(str_replace('__''.'substr($key9)))] = $value;
  479.             }
  480.         }
  481.         return $parameters;
  482.     }
  483.     /**
  484.      * Builds the service container.
  485.      *
  486.      * @return ContainerBuilder The compiled service container
  487.      *
  488.      * @throws \RuntimeException
  489.      */
  490.     protected function buildContainer()
  491.     {
  492.         foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
  493.             if (!is_dir($dir)) {
  494.                 if (false === @mkdir($dir0777true) && !is_dir($dir)) {
  495.                     throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n"$name$dir));
  496.                 }
  497.             } elseif (!is_writable($dir)) {
  498.                 throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n"$name$dir));
  499.             }
  500.         }
  501.         $container $this->getContainerBuilder();
  502.         $container->addObjectResource($this);
  503.         $this->prepareContainer($container);
  504.         if (null !== $cont $this->registerContainerConfiguration($this->getContainerLoader($container))) {
  505.             $container->merge($cont);
  506.         }
  507.         $container->addCompilerPass(new AddClassesToCachePass($this));
  508.         $container->addResource(new EnvParametersResource('SYMFONY__'));
  509.         return $container;
  510.     }
  511.     /**
  512.      * Prepares the ContainerBuilder before it is compiled.
  513.      *
  514.      * @param ContainerBuilder $container A ContainerBuilder instance
  515.      */
  516.     protected function prepareContainer(ContainerBuilder $container)
  517.     {
  518.         $extensions = array();
  519.         foreach ($this->bundles as $bundle) {
  520.             if ($extension $bundle->getContainerExtension()) {
  521.                 $container->registerExtension($extension);
  522.                 $extensions[] = $extension->getAlias();
  523.             }
  524.             if ($this->debug) {
  525.                 $container->addObjectResource($bundle);
  526.             }
  527.         }
  528.         foreach ($this->bundles as $bundle) {
  529.             $bundle->build($container);
  530.         }
  531.         // ensure these extensions are implicitly loaded
  532.         $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  533.     }
  534.     /**
  535.      * Gets a new ContainerBuilder instance used to build the service container.
  536.      *
  537.      * @return ContainerBuilder
  538.      */
  539.     protected function getContainerBuilder()
  540.     {
  541.         $container = new ContainerBuilder();
  542.         $container->getParameterBag()->add($this->getKernelParameters());
  543.         if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
  544.             $container->setProxyInstantiator(new RuntimeInstantiator());
  545.         }
  546.         return $container;
  547.     }
  548.     /**
  549.      * Dumps the service container to PHP code in the cache.
  550.      *
  551.      * @param ConfigCache      $cache     The config cache
  552.      * @param ContainerBuilder $container The service container
  553.      * @param string           $class     The name of the class to generate
  554.      * @param string           $baseClass The name of the container's base class
  555.      */
  556.     protected function dumpContainer(ConfigCache $cacheContainerBuilder $container$class$baseClass)
  557.     {
  558.         // cache the container
  559.         $dumper = new PhpDumper($container);
  560.         if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
  561.             $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
  562.         }
  563.         $content $dumper->dump(array('class' => $class'base_class' => $baseClass'file' => $cache->getPath(), 'debug' => $this->debug));
  564.         $cache->write($content$container->getResources());
  565.     }
  566.     /**
  567.      * Returns a loader for the container.
  568.      *
  569.      * @param ContainerInterface $container The service container
  570.      *
  571.      * @return DelegatingLoader The loader
  572.      */
  573.     protected function getContainerLoader(ContainerInterface $container)
  574.     {
  575.         $locator = new FileLocator($this);
  576.         $resolver = new LoaderResolver(array(
  577.             new XmlFileLoader($container$locator),
  578.             new YamlFileLoader($container$locator),
  579.             new IniFileLoader($container$locator),
  580.             new PhpFileLoader($container$locator),
  581.             new DirectoryLoader($container$locator),
  582.             new ClosureLoader($container),
  583.         ));
  584.         return new DelegatingLoader($resolver);
  585.     }
  586.     /**
  587.      * Removes comments from a PHP source string.
  588.      *
  589.      * We don't use the PHP php_strip_whitespace() function
  590.      * as we want the content to be readable and well-formatted.
  591.      *
  592.      * @param string $source A PHP string
  593.      *
  594.      * @return string The PHP string with the comments removed
  595.      */
  596.     public static function stripComments($source)
  597.     {
  598.         if (!function_exists('token_get_all')) {
  599.             return $source;
  600.         }
  601.         $rawChunk '';
  602.         $output '';
  603.         $tokens token_get_all($source);
  604.         $ignoreSpace false;
  605.         for ($i 0; isset($tokens[$i]); ++$i) {
  606.             $token $tokens[$i];
  607.             if (!isset($token[1]) || 'b"' === $token) {
  608.                 $rawChunk .= $token;
  609.             } elseif (T_START_HEREDOC === $token[0]) {
  610.                 $output .= $rawChunk.$token[1];
  611.                 do {
  612.                     $token $tokens[++$i];
  613.                     $output .= isset($token[1]) && 'b"' !== $token $token[1] : $token;
  614.                 } while ($token[0] !== T_END_HEREDOC);
  615.                 $rawChunk '';
  616.             } elseif (T_WHITESPACE === $token[0]) {
  617.                 if ($ignoreSpace) {
  618.                     $ignoreSpace false;
  619.                     continue;
  620.                 }
  621.                 // replace multiple new lines with a single newline
  622.                 $rawChunk .= preg_replace(array('/\n{2,}/S'), "\n"$token[1]);
  623.             } elseif (in_array($token[0], array(T_COMMENTT_DOC_COMMENT))) {
  624.                 $ignoreSpace true;
  625.             } else {
  626.                 $rawChunk .= $token[1];
  627.                 // The PHP-open tag already has a new-line
  628.                 if (T_OPEN_TAG === $token[0]) {
  629.                     $ignoreSpace true;
  630.                 }
  631.             }
  632.         }
  633.         $output .= $rawChunk;
  634.         if (\PHP_VERSION_ID >= 70000) {
  635.             // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
  636.             unset($tokens$rawChunk);
  637.             gc_mem_caches();
  638.         }
  639.         return $output;
  640.     }
  641.     public function serialize()
  642.     {
  643.         return serialize(array($this->environment$this->debug));
  644.     }
  645.     public function unserialize($data)
  646.     {
  647.         list($environment$debug) = unserialize($data);
  648.         $this->__construct($environment$debug);
  649.     }
  650. }