Augmentation vers version 3.3.0
This commit is contained in:
418
vendor/symfony/http-kernel/Kernel.php
vendored
418
vendor/symfony/http-kernel/Kernel.php
vendored
@@ -17,22 +17,25 @@ use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
|
||||
use Symfony\Component\HttpKernel\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
|
||||
/**
|
||||
@@ -42,12 +45,12 @@ use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfiguration
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
abstract class Kernel implements KernelInterface, RebootableInterface, TerminableInterface
|
||||
{
|
||||
/**
|
||||
* @var BundleInterface[]
|
||||
*/
|
||||
protected $bundles = array();
|
||||
protected $bundles = [];
|
||||
|
||||
protected $bundleMap;
|
||||
protected $container;
|
||||
@@ -59,15 +62,20 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
protected $startTime;
|
||||
protected $loadClassCache;
|
||||
|
||||
const VERSION = '2.8.49';
|
||||
const VERSION_ID = 20849;
|
||||
const MAJOR_VERSION = 2;
|
||||
const MINOR_VERSION = 8;
|
||||
const RELEASE_VERSION = 49;
|
||||
private $projectDir;
|
||||
private $warmupDir;
|
||||
private $requestStackSize = 0;
|
||||
private $resetServices = false;
|
||||
|
||||
const VERSION = '3.4.36';
|
||||
const VERSION_ID = 30436;
|
||||
const MAJOR_VERSION = 3;
|
||||
const MINOR_VERSION = 4;
|
||||
const RELEASE_VERSION = 36;
|
||||
const EXTRA_VERSION = '';
|
||||
|
||||
const END_OF_MAINTENANCE = '11/2018';
|
||||
const END_OF_LIFE = '11/2019';
|
||||
const END_OF_MAINTENANCE = '11/2020';
|
||||
const END_OF_LIFE = '11/2021';
|
||||
|
||||
/**
|
||||
* @param string $environment The environment
|
||||
@@ -79,36 +87,14 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$this->debug = (bool) $debug;
|
||||
$this->rootDir = $this->getRootDir();
|
||||
$this->name = $this->getName();
|
||||
|
||||
if ($this->debug) {
|
||||
$this->startTime = microtime(true);
|
||||
}
|
||||
|
||||
$defClass = new \ReflectionMethod($this, 'init');
|
||||
$defClass = $defClass->getDeclaringClass()->name;
|
||||
|
||||
if (__CLASS__ !== $defClass) {
|
||||
@trigger_error(sprintf('Calling the %s::init() method is deprecated since Symfony 2.3 and will be removed in 3.0. Move your logic to the constructor method instead.', $defClass), E_USER_DEPRECATED);
|
||||
$this->init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 2.3, to be removed in 3.0. Move your logic in the constructor instead.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.3 and will be removed in 3.0. Move your logic to the constructor method instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->debug) {
|
||||
$this->startTime = microtime(true);
|
||||
}
|
||||
|
||||
$this->booted = false;
|
||||
$this->container = null;
|
||||
$this->requestStackSize = 0;
|
||||
$this->resetServices = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,8 +103,26 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
public function boot()
|
||||
{
|
||||
if (true === $this->booted) {
|
||||
if (!$this->requestStackSize && $this->resetServices) {
|
||||
if ($this->container->has('services_resetter')) {
|
||||
$this->container->get('services_resetter')->reset();
|
||||
}
|
||||
$this->resetServices = false;
|
||||
if ($this->debug) {
|
||||
$this->startTime = microtime(true);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if ($this->debug) {
|
||||
$this->startTime = microtime(true);
|
||||
}
|
||||
if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
|
||||
putenv('SHELL_VERBOSITY=3');
|
||||
$_ENV['SHELL_VERBOSITY'] = 3;
|
||||
$_SERVER['SHELL_VERBOSITY'] = 3;
|
||||
}
|
||||
|
||||
if ($this->loadClassCache) {
|
||||
$this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
|
||||
@@ -138,6 +142,16 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$this->booted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reboot($warmupDir)
|
||||
{
|
||||
$this->shutdown();
|
||||
$this->warmupDir = $warmupDir;
|
||||
$this->boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -169,6 +183,8 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
}
|
||||
|
||||
$this->container = null;
|
||||
$this->requestStackSize = 0;
|
||||
$this->resetServices = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,17 +192,21 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
if (false === $this->booted) {
|
||||
$this->boot();
|
||||
}
|
||||
$this->boot();
|
||||
++$this->requestStackSize;
|
||||
$this->resetServices = true;
|
||||
|
||||
return $this->getHttpKernel()->handle($request, $type, $catch);
|
||||
try {
|
||||
return $this->getHttpKernel()->handle($request, $type, $catch);
|
||||
} finally {
|
||||
--$this->requestStackSize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a HTTP kernel from the container.
|
||||
*
|
||||
* @return HttpKernel
|
||||
* @return HttpKernelInterface
|
||||
*/
|
||||
protected function getHttpKernel()
|
||||
{
|
||||
@@ -203,27 +223,18 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated since version 2.6, to be removed in 3.0.
|
||||
*/
|
||||
public function isClassInActiveBundle($class)
|
||||
public function getBundle($name, $first = true/*, $noDeprecation = false */)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.6 and will be removed in version 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
foreach ($this->getBundles() as $bundle) {
|
||||
if (0 === strpos($class, $bundle->getNamespace())) {
|
||||
return true;
|
||||
}
|
||||
$noDeprecation = false;
|
||||
if (\func_num_args() >= 3) {
|
||||
$noDeprecation = func_get_arg(2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!$first && !$noDeprecation) {
|
||||
@trigger_error(sprintf('Passing "false" as the second argument to "%s()" is deprecated as of 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBundle($name, $first = true)
|
||||
{
|
||||
if (!isset($this->bundleMap[$name])) {
|
||||
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, \get_class($this)));
|
||||
}
|
||||
@@ -259,8 +270,8 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
|
||||
$overridePath = substr($path, 9);
|
||||
$resourceBundle = null;
|
||||
$bundles = $this->getBundle($bundleName, false);
|
||||
$files = array();
|
||||
$bundles = $this->getBundle($bundleName, false, true);
|
||||
$files = [];
|
||||
|
||||
foreach ($bundles as $bundle) {
|
||||
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
|
||||
@@ -334,6 +345,33 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
return $this->rootDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application root dir (path of the project's composer file).
|
||||
*
|
||||
* @return string The project root dir
|
||||
*/
|
||||
public function getProjectDir()
|
||||
{
|
||||
if (null === $this->projectDir) {
|
||||
$r = new \ReflectionObject($this);
|
||||
|
||||
if (!file_exists($dir = $r->getFileName())) {
|
||||
throw new \LogicException(sprintf('Cannot auto-detect project dir for kernel of class "%s".', $r->name));
|
||||
}
|
||||
|
||||
$dir = $rootDir = \dirname($dir);
|
||||
while (!file_exists($dir.'/composer.json')) {
|
||||
if ($dir === \dirname($dir)) {
|
||||
return $this->projectDir = $rootDir;
|
||||
}
|
||||
$dir = \dirname($dir);
|
||||
}
|
||||
$this->projectDir = $dir;
|
||||
}
|
||||
|
||||
return $this->projectDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -353,18 +391,38 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*
|
||||
* @param string $name The cache name prefix
|
||||
* @param string $extension File extension of the resulting file
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. The class cache is not needed anymore when using PHP 7.0.
|
||||
*/
|
||||
public function loadClassCache($name = 'classes', $extension = '.php')
|
||||
{
|
||||
$this->loadClassCache = array($name, $extension);
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->loadClassCache = [$name, $extension];
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally.
|
||||
* @internal
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setClassCache(array $classes)
|
||||
{
|
||||
file_put_contents($this->getCacheDir().'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function setAnnotatedClassCache(array $annotatedClasses)
|
||||
{
|
||||
file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/annotations.map', sprintf('<?php return %s;', var_export($annotatedClasses, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,7 +430,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
public function getStartTime()
|
||||
{
|
||||
return $this->debug ? $this->startTime : -INF;
|
||||
return $this->debug && null !== $this->startTime ? $this->startTime : -INF;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,10 +457,18 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
protected function doLoadClassCache($name, $extension)
|
||||
{
|
||||
if (!$this->booted && is_file($this->getCacheDir().'/classes.map')) {
|
||||
ClassCollectionLoader::load(include($this->getCacheDir().'/classes.map'), $this->getCacheDir(), $name, $this->debug, false, $extension);
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
$cacheDir = $this->warmupDir ?: $this->getCacheDir();
|
||||
|
||||
if (!$this->booted && is_file($cacheDir.'/classes.map')) {
|
||||
ClassCollectionLoader::load(include($cacheDir.'/classes.map'), $cacheDir, $name, $this->debug, false, $extension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,9 +486,9 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
protected function initializeBundles()
|
||||
{
|
||||
// init bundles
|
||||
$this->bundles = array();
|
||||
$topMostBundles = array();
|
||||
$directChildren = array();
|
||||
$this->bundles = [];
|
||||
$topMostBundles = [];
|
||||
$directChildren = [];
|
||||
|
||||
foreach ($this->registerBundles() as $bundle) {
|
||||
$name = $bundle->getName();
|
||||
@@ -432,6 +498,8 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$this->bundles[$name] = $bundle;
|
||||
|
||||
if ($parentName = $bundle->getParent()) {
|
||||
@trigger_error('Bundle inheritance is deprecated as of 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
|
||||
if (isset($directChildren[$parentName])) {
|
||||
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
|
||||
}
|
||||
@@ -452,10 +520,10 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
}
|
||||
|
||||
// inheritance
|
||||
$this->bundleMap = array();
|
||||
$this->bundleMap = [];
|
||||
foreach ($topMostBundles as $name => $bundle) {
|
||||
$bundleMap = array($bundle);
|
||||
$hierarchy = array($name);
|
||||
$bundleMap = [$bundle];
|
||||
$hierarchy = [$name];
|
||||
|
||||
while (isset($directChildren[$name])) {
|
||||
$name = $directChildren[$name];
|
||||
@@ -470,6 +538,15 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension point similar to the Bundle::build() method.
|
||||
*
|
||||
* Use this method to register compiler passes and manipulate the container during the building process.
|
||||
*/
|
||||
protected function build(ContainerBuilder $container)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the container class.
|
||||
*
|
||||
@@ -501,22 +578,111 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
protected function initializeContainer()
|
||||
{
|
||||
$class = $this->getContainerClass();
|
||||
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
|
||||
$fresh = true;
|
||||
if (!$cache->isFresh()) {
|
||||
$container = $this->buildContainer();
|
||||
$container->compile();
|
||||
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
|
||||
|
||||
$fresh = false;
|
||||
$cacheDir = $this->warmupDir ?: $this->getCacheDir();
|
||||
$cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug);
|
||||
$oldContainer = null;
|
||||
if ($fresh = $cache->isFresh()) {
|
||||
// Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
|
||||
$errorLevel = error_reporting(\E_ALL ^ \E_WARNING);
|
||||
$fresh = $oldContainer = false;
|
||||
try {
|
||||
if (file_exists($cache->getPath()) && \is_object($this->container = include $cache->getPath())) {
|
||||
$this->container->set('kernel', $this);
|
||||
$oldContainer = $this->container;
|
||||
$fresh = true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
} catch (\Exception $e) {
|
||||
} finally {
|
||||
error_reporting($errorLevel);
|
||||
}
|
||||
}
|
||||
|
||||
require_once $cache->getPath();
|
||||
if ($fresh) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->container = new $class();
|
||||
if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
|
||||
$collectedLogs = [];
|
||||
$previousHandler = set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) {
|
||||
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
|
||||
return $previousHandler ? $previousHandler($type, $message, $file, $line) : false;
|
||||
}
|
||||
|
||||
if (isset($collectedLogs[$message])) {
|
||||
++$collectedLogs[$message]['count'];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
|
||||
// Clean the trace by removing first frames added by the error handler itself.
|
||||
for ($i = 0; isset($backtrace[$i]); ++$i) {
|
||||
if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
|
||||
$backtrace = \array_slice($backtrace, 1 + $i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$collectedLogs[$message] = [
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'file' => $file,
|
||||
'line' => $line,
|
||||
'trace' => $backtrace,
|
||||
'count' => 1,
|
||||
];
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
$container = null;
|
||||
$container = $this->buildContainer();
|
||||
$container->compile();
|
||||
} finally {
|
||||
if ($collectDeprecations) {
|
||||
restore_error_handler();
|
||||
|
||||
file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs)));
|
||||
file_put_contents($cacheDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : '');
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $oldContainer && file_exists($cache->getPath())) {
|
||||
$errorLevel = error_reporting(\E_ALL ^ \E_WARNING);
|
||||
try {
|
||||
$oldContainer = include $cache->getPath();
|
||||
} catch (\Throwable $e) {
|
||||
} catch (\Exception $e) {
|
||||
} finally {
|
||||
error_reporting($errorLevel);
|
||||
}
|
||||
}
|
||||
$oldContainer = \is_object($oldContainer) ? new \ReflectionClass($oldContainer) : false;
|
||||
|
||||
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
|
||||
$this->container = require $cache->getPath();
|
||||
$this->container->set('kernel', $this);
|
||||
|
||||
if (!$fresh && $this->container->has('cache_warmer')) {
|
||||
if ($oldContainer && \get_class($this->container) !== $oldContainer->name) {
|
||||
// Because concurrent requests might still be using them,
|
||||
// old container files are not removed immediately,
|
||||
// but on a next dump of the container.
|
||||
static $legacyContainers = [];
|
||||
$oldContainerDir = \dirname($oldContainer->getFileName());
|
||||
$legacyContainers[$oldContainerDir.'.legacy'] = true;
|
||||
foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy', GLOB_NOSORT) as $legacyContainer) {
|
||||
if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
|
||||
(new Filesystem())->remove(substr($legacyContainer, 0, -7));
|
||||
}
|
||||
}
|
||||
|
||||
touch($oldContainerDir.'.legacy');
|
||||
}
|
||||
|
||||
if ($this->container->has('cache_warmer')) {
|
||||
$this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
|
||||
}
|
||||
}
|
||||
@@ -528,32 +694,33 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
protected function getKernelParameters()
|
||||
{
|
||||
$bundles = array();
|
||||
$bundlesMetadata = array();
|
||||
$bundles = [];
|
||||
$bundlesMetadata = [];
|
||||
|
||||
foreach ($this->bundles as $name => $bundle) {
|
||||
$bundles[$name] = \get_class($bundle);
|
||||
$bundlesMetadata[$name] = array(
|
||||
$bundlesMetadata[$name] = [
|
||||
'parent' => $bundle->getParent(),
|
||||
'path' => $bundle->getPath(),
|
||||
'namespace' => $bundle->getNamespace(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
[
|
||||
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
|
||||
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
|
||||
'kernel.environment' => $this->environment,
|
||||
'kernel.debug' => $this->debug,
|
||||
'kernel.name' => $this->name,
|
||||
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
|
||||
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
|
||||
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
|
||||
'kernel.bundles' => $bundles,
|
||||
'kernel.bundles_metadata' => $bundlesMetadata,
|
||||
'kernel.charset' => $this->getCharset(),
|
||||
'kernel.container_class' => $this->getContainerClass(),
|
||||
),
|
||||
$this->getEnvParameters()
|
||||
],
|
||||
$this->getEnvParameters(false)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -563,12 +730,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
* Only the parameters starting with "SYMFONY__" are considered.
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
protected function getEnvParameters()
|
||||
{
|
||||
$parameters = array();
|
||||
if (0 === \func_num_args() || func_get_arg(0)) {
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax to get the value of any environment variable from configuration files instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$parameters = [];
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
if (0 === strpos($key, 'SYMFONY__')) {
|
||||
@trigger_error(sprintf('The support of special environment variables that start with SYMFONY__ (such as "%s") is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax instead to get the value of environment variables in configuration files.', $key), E_USER_DEPRECATED);
|
||||
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
|
||||
}
|
||||
}
|
||||
@@ -585,7 +759,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
protected function buildContainer()
|
||||
{
|
||||
foreach (array('cache' => $this->getCacheDir(), 'logs' => $this->getLogDir()) as $name => $dir) {
|
||||
foreach (['cache' => $this->warmupDir ?: $this->getCacheDir(), 'logs' => $this->getLogDir()] as $name => $dir) {
|
||||
if (!is_dir($dir)) {
|
||||
if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
|
||||
throw new \RuntimeException(sprintf("Unable to create the %s directory (%s)\n", $name, $dir));
|
||||
@@ -603,7 +777,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$container->merge($cont);
|
||||
}
|
||||
|
||||
$container->addCompilerPass(new AddClassesToCachePass($this));
|
||||
$container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
|
||||
$container->addResource(new EnvParametersResource('SYMFONY__'));
|
||||
|
||||
return $container;
|
||||
@@ -614,21 +788,27 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
protected function prepareContainer(ContainerBuilder $container)
|
||||
{
|
||||
$extensions = array();
|
||||
$extensions = [];
|
||||
foreach ($this->bundles as $bundle) {
|
||||
if ($extension = $bundle->getContainerExtension()) {
|
||||
$container->registerExtension($extension);
|
||||
$extensions[] = $extension->getAlias();
|
||||
}
|
||||
|
||||
if ($this->debug) {
|
||||
$container->addObjectResource($bundle);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->bundles as $bundle) {
|
||||
$bundle->build($container);
|
||||
}
|
||||
|
||||
$this->build($container);
|
||||
|
||||
foreach ($container->getExtensions() as $extension) {
|
||||
$extensions[] = $extension->getAlias();
|
||||
}
|
||||
|
||||
// ensure these extensions are implicitly loaded
|
||||
$container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
|
||||
}
|
||||
@@ -640,8 +820,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
*/
|
||||
protected function getContainerBuilder()
|
||||
{
|
||||
$container = new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
|
||||
$container = new ContainerBuilder();
|
||||
$container->getParameterBag()->add($this->getKernelParameters());
|
||||
|
||||
if ($this instanceof CompilerPassInterface) {
|
||||
$container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
|
||||
}
|
||||
if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) {
|
||||
$container->setProxyInstantiator(new RuntimeInstantiator());
|
||||
}
|
||||
@@ -663,12 +847,33 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) {
|
||||
$dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath())));
|
||||
$dumper->setProxyDumper(new ProxyDumper());
|
||||
}
|
||||
|
||||
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath(), 'debug' => $this->debug));
|
||||
$content = $dumper->dump([
|
||||
'class' => $class,
|
||||
'base_class' => $baseClass,
|
||||
'file' => $cache->getPath(),
|
||||
'as_files' => true,
|
||||
'debug' => $this->debug,
|
||||
'inline_class_loader_parameter' => \PHP_VERSION_ID >= 70000 && !$this->loadClassCache && !class_exists(ClassCollectionLoader::class, false) ? 'container.dumper.inline_class_loader' : null,
|
||||
'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
|
||||
]);
|
||||
|
||||
$cache->write($content, $container->getResources());
|
||||
$rootCode = array_pop($content);
|
||||
$dir = \dirname($cache->getPath()).'/';
|
||||
$fs = new Filesystem();
|
||||
|
||||
foreach ($content as $file => $code) {
|
||||
$fs->dumpFile($dir.$file, $code);
|
||||
@chmod($dir.$file, 0666 & ~umask());
|
||||
}
|
||||
$legacyFile = \dirname($dir.key($content)).'.legacy';
|
||||
if (file_exists($legacyFile)) {
|
||||
@unlink($legacyFile);
|
||||
}
|
||||
|
||||
$cache->write($rootCode, $container->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -679,14 +884,15 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
protected function getContainerLoader(ContainerInterface $container)
|
||||
{
|
||||
$locator = new FileLocator($this);
|
||||
$resolver = new LoaderResolver(array(
|
||||
$resolver = new LoaderResolver([
|
||||
new XmlFileLoader($container, $locator),
|
||||
new YamlFileLoader($container, $locator),
|
||||
new IniFileLoader($container, $locator),
|
||||
new PhpFileLoader($container, $locator),
|
||||
new GlobFileLoader($container, $locator),
|
||||
new DirectoryLoader($container, $locator),
|
||||
new ClosureLoader($container),
|
||||
));
|
||||
]);
|
||||
|
||||
return new DelegatingLoader($resolver);
|
||||
}
|
||||
@@ -730,8 +936,8 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
}
|
||||
|
||||
// replace multiple new lines with a single newline
|
||||
$rawChunk .= preg_replace(array('/\n{2,}/S'), "\n", $token[1]);
|
||||
} elseif (\in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
||||
$rawChunk .= preg_replace(['/\n{2,}/S'], "\n", $token[1]);
|
||||
} elseif (\in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
|
||||
$ignoreSpace = true;
|
||||
} else {
|
||||
$rawChunk .= $token[1];
|
||||
@@ -756,12 +962,16 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array($this->environment, $this->debug));
|
||||
return serialize([$this->environment, $this->debug]);
|
||||
}
|
||||
|
||||
public function unserialize($data)
|
||||
{
|
||||
list($environment, $debug) = unserialize($data);
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
list($environment, $debug) = unserialize($data, ['allowed_classes' => false]);
|
||||
} else {
|
||||
list($environment, $debug) = unserialize($data);
|
||||
}
|
||||
|
||||
$this->__construct($environment, $debug);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user