Merge branch '3.4' into 4.0

* 3.4:
  [HttpKernel] Better handling of legacy cache
  modify definitions only if the do exist
  [DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist
  [FrameworkBundle] Make MicroKernelTraitTest green
  don't override existing verbosity env var
  [HttpKernel] Read $_ENV when checking SHELL_VERBOSITY
  Remove unreachable code
  Automatically enable the CSRF protection if CSRF manager exists
  bumped Symfony version to 3.4.0
  adding checks for the expression language
  updated VERSION for 3.4.0-RC2
  updated CHANGELOG for 3.4.0-RC2
This commit is contained in:
Christian Flothmann 2017-11-28 23:05:27 +01:00
commit d2496ab5d2
12 changed files with 50 additions and 16 deletions

View File

@ -21,6 +21,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Lock\Lock;
use Symfony\Component\Lock\Store\SemaphoreStore;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\Validation;
@ -109,7 +110,7 @@ class Configuration implements ConfigurationInterface
$rootNode
->children()
->arrayNode('csrf_protection')
->canBeEnabled()
->{!class_exists(FullStack::class) && class_exists(CsrfTokenManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->end()
;

View File

@ -18,7 +18,7 @@ class MicroKernelTraitTest extends TestCase
{
public function test()
{
$kernel = new ConcreteMicroKernel('test', true);
$kernel = new ConcreteMicroKernel('test', false);
$kernel->boot();
$request = Request::create('/');
@ -31,7 +31,7 @@ class MicroKernelTraitTest extends TestCase
public function testAsEventSubscriber()
{
$kernel = new ConcreteMicroKernel('test', true);
$kernel = new ConcreteMicroKernel('test', false);
$kernel->boot();
$request = Request::create('/danger');

View File

@ -74,9 +74,6 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
if ($optionalBehavior = '?' === $type[0]) {
$type = substr($type, 1);
$optionalBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
} elseif ($optionalBehavior = '!' === $type[0]) {
$type = substr($type, 1);
$optionalBehavior = ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE;
}
if (is_int($key)) {
$key = $type;

View File

@ -375,7 +375,7 @@ EOTXT
if (isset($lineage[$class])) {
return;
}
if (!$r = $this->container->getReflectionClass($class)) {
if (!$r = $this->container->getReflectionClass($class, false)) {
return;
}
if ($this->container instanceof $class) {

View File

@ -488,6 +488,10 @@ class XmlFileLoader extends FileLoader
$arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior);
break;
case 'expression':
if (!class_exists(Expression::class)) {
throw new \LogicException(sprintf('The type="expression" attribute cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".'));
}
$arguments[$key] = new Expression($arg->nodeValue);
break;
case 'collection':

View File

@ -727,6 +727,10 @@ class YamlFileLoader extends FileLoader
$value[$k] = $this->resolveServices($v, $file, $isParameter);
}
} elseif (is_string($value) && 0 === strpos($value, '@=')) {
if (!class_exists(Expression::class)) {
throw new \LogicException(sprintf('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".'));
}
return new Expression(substr($value, 2));
} elseif (is_string($value) && 0 === strpos($value, '@')) {
if (0 === strpos($value, '@@')) {

View File

@ -0,0 +1,7 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
class ParentNotExists extends \NotExists
{
}

View File

@ -7,11 +7,13 @@ use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath;
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
$container = new ContainerBuilder();
$container->register(HotPath\C1::class)->addTag('container.hot_path')->setPublic(true);
$container->register(HotPath\C2::class)->addArgument(new Reference(HotPath\C3::class))->setPublic(true);
$container->register(HotPath\C3::class);
$container->register(ParentNotExists::class)->setPublic(true);
return $container;

View File

@ -30,6 +30,7 @@ class ProjectServiceContainer extends Container
$this->services = $this->privates = array();
$this->methodMap = array(
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists' => 'getParentNotExistsService',
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1' => 'getC1Service',
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2' => 'getC2Service',
);
@ -67,6 +68,16 @@ class ProjectServiceContainer extends Container
);
}
/**
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists' shared service.
*
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists
*/
protected function getParentNotExistsService()
{
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists();
}
/**
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C1' shared service.
*

View File

@ -112,7 +112,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
return;
}
if ($this->debug && !isset($_SERVER['SHELL_VERBOSITY'])) {
if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
putenv('SHELL_VERBOSITY=3');
$_ENV['SHELL_VERBOSITY'] = 3;
$_SERVER['SHELL_VERBOSITY'] = 3;
@ -451,8 +451,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$class = $this->getContainerClass();
$cacheDir = $this->warmupDir ?: $this->getCacheDir();
$cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug);
$fresh = true;
if (!$cache->isFresh()) {
if ($fresh = $cache->isFresh()) {
$this->container = require $cache->getPath();
$fresh = \is_object($this->container);
}
if (!$fresh) {
if ($this->debug) {
$collectedLogs = array();
$previousHandler = set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) {
@ -502,11 +505,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$oldContainer = file_exists($cache->getPath()) && is_object($oldContainer = @include $cache->getPath()) ? new \ReflectionClass($oldContainer) : false;
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
$fresh = false;
$this->container = require $cache->getPath();
}
$this->container = require $cache->getPath();
$this->container->set('kernel', $this);
if ($fresh) {

View File

@ -42,8 +42,8 @@ class Logger extends AbstractLogger
if (null === $minLevel) {
$minLevel = LogLevel::WARNING;
if (isset($_SERVER['SHELL_VERBOSITY'])) {
switch ((int) $_SERVER['SHELL_VERBOSITY']) {
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) {
case -1: $minLevel = LogLevel::ERROR; break;
case 1: $minLevel = LogLevel::NOTICE; break;
case 2: $minLevel = LogLevel::INFO; break;

View File

@ -64,8 +64,15 @@ class TranslatorPass implements CompilerPassInterface
->replaceArgument(3, $loaders)
;
if ($container->hasParameter('twig.default_path')) {
if (!$container->hasParameter('twig.default_path')) {
return;
}
if ($container->hasDefinition($this->debugCommandServiceId)) {
$container->getDefinition($this->debugCommandServiceId)->replaceArgument(4, $container->getParameter('twig.default_path'));
}
if ($container->hasDefinition($this->updateCommandServiceId)) {
$container->getDefinition($this->updateCommandServiceId)->replaceArgument(5, $container->getParameter('twig.default_path'));
}
}