Issue #2712647 by klausi, catch, slasher13, jibran, Manuel Garcia, alexpott, naveenvalecha, neclimdul, dawehner, Wim Leers, pounard: Update Symfony components to ~3.1

8.3.x
Alex Pott 2016-12-01 11:00:20 +00:00
parent 6e26b862de
commit a55b8ef19e
30 changed files with 334 additions and 654 deletions

608
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,20 +5,20 @@
"license": "GPL-2.0+", "license": "GPL-2.0+",
"require": { "require": {
"php": ">=5.5.9", "php": ">=5.5.9",
"symfony/class-loader": "~2.8", "symfony/class-loader": "~3.1",
"symfony/console": "~2.8", "symfony/console": "~3.1",
"symfony/dependency-injection": "~2.8", "symfony/dependency-injection": "~3.1",
"symfony/dom-crawler": ">=2.8.13 <3.0", "symfony/dom-crawler": ">=3.1.6 <4.0",
"symfony/event-dispatcher": "~2.8", "symfony/event-dispatcher": "~3.1",
"symfony/http-foundation": "~2.8", "symfony/http-foundation": ">=3.1.6 <4.0",
"symfony/http-kernel": "~2.8", "symfony/http-kernel": "~3.1",
"symfony/routing": "~2.8", "symfony/routing": "~3.1",
"symfony/serializer": "~2.8", "symfony/serializer": "~3.1",
"symfony/translation": "~2.8", "symfony/translation": "~3.1",
"symfony/validator": "~2.8", "symfony/validator": "~3.1",
"symfony/process": "~2.8", "symfony/process": "~3.1",
"symfony/polyfill-iconv": "~1.0", "symfony/polyfill-iconv": "~1.0",
"symfony/yaml": "~2.8", "symfony/yaml": "~3.1",
"twig/twig": "^1.23.1", "twig/twig": "^1.23.1",
"doctrine/common": "2.5.*", "doctrine/common": "2.5.*",
"doctrine/annotations": "1.2.*", "doctrine/annotations": "1.2.*",
@ -42,7 +42,7 @@
"jcalderonzumba/mink-phantomjs-driver": "~0.3.1", "jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
"mikey179/vfsStream": "~1.2", "mikey179/vfsStream": "~1.2",
"phpunit/phpunit": "~4.8", "phpunit/phpunit": "~4.8",
"symfony/css-selector": "~2.8" "symfony/css-selector": "~3.1"
}, },
"replace": { "replace": {
"drupal/action": "self.version", "drupal/action": "self.version",

View File

@ -3,9 +3,7 @@
namespace Drupal\Component\DependencyInjection; namespace Drupal\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
use Symfony\Component\DependencyInjection\ResettableContainerInterface; use Symfony\Component\DependencyInjection\ResettableContainerInterface;
use Symfony\Component\DependencyInjection\ScopeInterface;
use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -50,7 +48,7 @@ use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceExce
* *
* @ingroup container * @ingroup container
*/ */
class Container implements IntrospectableContainerInterface, ResettableContainerInterface { class Container implements ContainerInterface, ResettableContainerInterface {
/** /**
* The parameters of the container. * The parameters of the container.
@ -361,11 +359,7 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function set($id, $service, $scope = ContainerInterface::SCOPE_CONTAINER) { public function set($id, $service) {
if (!in_array($scope, array('container', 'request')) || ('request' === $scope && 'request' !== $id)) {
@trigger_error('The concept of container scopes is deprecated since version 2.8 and will be removed in 3.0. Omit the third parameter.', E_USER_DEPRECATED);
}
$this->services[$id] = $service; $this->services[$id] = $service;
} }
@ -587,61 +581,6 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
return $this->getAlternatives($name, array_keys($this->parameters)); return $this->getAlternatives($name, array_keys($this->parameters));
} }
/**
* {@inheritdoc}
*/
public function enterScope($name) {
if ('request' !== $name) {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
}
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
}
/**
* {@inheritdoc}
*/
public function leaveScope($name) {
if ('request' !== $name) {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
}
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
}
/**
* {@inheritdoc}
*/
public function addScope(ScopeInterface $scope) {
$name = $scope->getName();
if ('request' !== $name) {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
}
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
}
/**
* {@inheritdoc}
*/
public function hasScope($name) {
if ('request' !== $name) {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
}
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
}
/**
* {@inheritdoc}
*/
public function isScopeActive($name) {
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
}
/** /**
* Gets all defined service IDs. * Gets all defined service IDs.
* *

View File

@ -236,18 +236,6 @@ class OptimizedPhpArrayDumper extends Dumper {
$service['calls'] = $this->dumpMethodCalls($definition->getMethodCalls()); $service['calls'] = $this->dumpMethodCalls($definition->getMethodCalls());
} }
if (($scope = $definition->getScope()) !== ContainerInterface::SCOPE_CONTAINER) {
if ($scope === ContainerInterface::SCOPE_PROTOTYPE) {
// Scope prototype has been replaced with 'shared' => FALSE.
// This is a Symfony 2.8 forward compatibility fix.
// Reference: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#dependencyinjection
$service['shared'] = FALSE;
}
else {
throw new InvalidArgumentException("The 'scope' definition is deprecated in Symfony 3.0 and not supported by Drupal 8.");
}
}
// By default services are shared, so just provide the flag, when needed. // By default services are shared, so just provide the flag, when needed.
if ($definition->isShared() === FALSE) { if ($definition->isShared() === FALSE) {
$service['shared'] = $definition->isShared(); $service['shared'] = $definition->isShared();

View File

@ -2,7 +2,7 @@
namespace Drupal\Component\EventDispatcher; namespace Drupal\Component\EventDispatcher;
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -36,7 +36,7 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
/** /**
* The service container. * The service container.
* *
* @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface; * @var \Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
protected $container; protected $container;
@ -66,7 +66,7 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
/** /**
* Constructs a container aware event dispatcher. * Constructs a container aware event dispatcher.
* *
* @param \Symfony\Component\DependencyInjection\IntrospectableContainerInterface $container * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container. * The service container.
* @param array $listeners * @param array $listeners
* A nested array of listener definitions keyed by event name and priority. * A nested array of listener definitions keyed by event name and priority.
@ -77,7 +77,7 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
* A service entry will be resolved to a callable only just before its * A service entry will be resolved to a callable only just before its
* invocation. * invocation.
*/ */
public function __construct(IntrospectableContainerInterface $container, array $listeners = []) { public function __construct(ContainerInterface $container, array $listeners = []) {
$this->container = $container; $this->container = $container;
$this->listeners = $listeners; $this->listeners = $listeners;
$this->unsorted = []; $this->unsorted = [];
@ -91,9 +91,6 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
$event = new Event(); $event = new Event();
} }
$event->setDispatcher($this);
$event->setName($event_name);
if (isset($this->listeners[$event_name])) { if (isset($this->listeners[$event_name])) {
// Sort listeners if necessary. // Sort listeners if necessary.
if (isset($this->unsorted[$event_name])) { if (isset($this->unsorted[$event_name])) {

View File

@ -27,6 +27,13 @@ class YamlPecl implements SerializationInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function decode($raw) { public static function decode($raw) {
static $init;
if (!isset($init)) {
// Decode binary, since Symfony YAML parser encodes binary from 3.1
// onwards.
ini_set('yaml.decode_binary', 1);
$init = TRUE;
}
// yaml_parse() will error with an empty value. // yaml_parse() will error with an empty value.
if (!trim($raw)) { if (!trim($raw)) {
return NULL; return NULL;

View File

@ -5,6 +5,7 @@ namespace Drupal\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
/** /**
* Default serialization for YAML using the Symfony component. * Default serialization for YAML using the Symfony component.
@ -18,7 +19,7 @@ class YamlSymfony implements SerializationInterface {
try { try {
$yaml = new Dumper(); $yaml = new Dumper();
$yaml->setIndentation(2); $yaml->setIndentation(2);
return $yaml->dump($data, PHP_INT_MAX, 0, TRUE, FALSE); return $yaml->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
} }
catch (\Exception $e) { catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
@ -33,7 +34,7 @@ class YamlSymfony implements SerializationInterface {
$yaml = new Parser(); $yaml = new Parser();
// Make sure we have a single trailing newline. A very simple config like // Make sure we have a single trailing newline. A very simple config like
// 'foo: bar' with no newline will fail to parse otherwise. // 'foo: bar' with no newline will fail to parse otherwise.
return $yaml->parse($raw, TRUE, FALSE); return $yaml->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
} }
catch (\Exception $e) { catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);

View File

@ -3,7 +3,6 @@
namespace Drupal\Core\DependencyInjection; namespace Drupal\Core\DependencyInjection;
use Drupal\Component\DependencyInjection\Container as DrupalContainer; use Drupal\Component\DependencyInjection\Container as DrupalContainer;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Extends the Drupal container to set the service ID on the created object. * Extends the Drupal container to set the service ID on the created object.
@ -13,8 +12,8 @@ class Container extends DrupalContainer {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function set($id, $service, $scope = ContainerInterface::SCOPE_CONTAINER) { public function set($id, $service) {
parent::set($id, $service, $scope); parent::set($id, $service);
// Ensure that the _serviceId property is set on synthetic services as well. // Ensure that the _serviceId property is set on synthetic services as well.
if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) { if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {

View File

@ -46,20 +46,12 @@ class ContainerBuilder extends SymfonyContainerBuilder {
} }
/** /**
* Direct copy of the parent function. * {@inheritdoc}
*/ */
protected function shareService(Definition $definition, $service, $id) protected function shareService(Definition $definition, $service, $id)
{ {
if ($definition->isShared() && self::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) { if ($definition->isShared()) {
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
throw new InactiveScopeException($id, $scope);
}
$this->services[$lowerId = strtolower($id)] = $service; $this->services[$lowerId = strtolower($id)] = $service;
if (self::SCOPE_CONTAINER !== $scope) {
$this->scopedServices[$scope][$lowerId] = $service;
}
} }
} }
@ -74,11 +66,11 @@ class ContainerBuilder extends SymfonyContainerBuilder {
* ContainerBuilder class should be fixed to allow setting synthetic * ContainerBuilder class should be fixed to allow setting synthetic
* services in a frozen builder. * services in a frozen builder.
*/ */
public function set($id, $service, $scope = self::SCOPE_CONTAINER) { public function set($id, $service) {
if (strtolower($id) !== $id) { if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: $id"); throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
} }
SymfonyContainer::set($id, $service, $scope); SymfonyContainer::set($id, $service);
// Ensure that the _serviceId property is set on synthetic services as well. // Ensure that the _serviceId property is set on synthetic services as well.
if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) { if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {

View File

@ -151,6 +151,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
*/ */
protected $classLoader; protected $classLoader;
/**
* The class loader class before including settings.php.
*
* @var string
*/
protected $preSettingsClassLoaderClass;
/** /**
* Config storage object used for reading enabled modules configuration. * Config storage object used for reading enabled modules configuration.
* *
@ -890,6 +897,34 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
$container = new $class($container_definition); $container = new $class($container_definition);
} }
// If the class loader is still the same as before including settings.php
// use an optimised classloader if possible.
if ($this->preSettingsClassLoaderClass == get_class($this->classLoader)
&& Settings::get('class_loader_auto_detect', TRUE)) {
$prefix = Settings::getApcuPrefix('class_loader', $this->root);
// We have to key by module list since if this changes the classloader
// might have negative caches for classes that now exist.
$prefix .= '.' . hash('sha1', serialize(array_keys($container->getParameter('container.modules'))));
$loader = NULL;
// We autodetect one of the following three optimized classloaders, if
// their underlying extension exists.
if (function_exists('apcu_fetch')) {
$loader = new ApcClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('wincache')) {
$loader = new WinCacheClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('xcache')) {
$loader = new XcacheClassLoader($prefix, $this->classLoader);
}
if (!empty($loader)) {
$this->classLoader->unregister();
$loader->register();
$this->classLoader = $loader;
}
}
$this->attachSynthetic($container); $this->attachSynthetic($container);
$this->container = $container; $this->container = $container;
@ -1018,7 +1053,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
protected function initializeSettings(Request $request) { protected function initializeSettings(Request $request) {
$site_path = static::findSitePath($request); $site_path = static::findSitePath($request);
$this->setSitePath($site_path); $this->setSitePath($site_path);
$class_loader_class = get_class($this->classLoader); $this->preSettingsClassLoaderClass = get_class($this->classLoader);
Settings::initialize($this->root, $site_path, $this->classLoader); Settings::initialize($this->root, $site_path, $this->classLoader);
// Initialize our list of trusted HTTP Host headers to protect against // Initialize our list of trusted HTTP Host headers to protect against
@ -1029,31 +1064,6 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
throw new BadRequestHttpException('The provided host name is not valid for this server.'); throw new BadRequestHttpException('The provided host name is not valid for this server.');
} }
} }
// If the class loader is still the same, possibly
// upgrade to an optimized class loader.
if ($class_loader_class == get_class($this->classLoader)
&& Settings::get('class_loader_auto_detect', TRUE)) {
$prefix = Settings::getApcuPrefix('class_loader', $this->root);
$loader = NULL;
// We autodetect one of the following three optimized classloaders, if
// their underlying extension exists.
if (function_exists('apcu_fetch')) {
$loader = new ApcClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('wincache')) {
$loader = new WinCacheClassLoader($prefix, $this->classLoader);
}
elseif (extension_loaded('xcache')) {
$loader = new XcacheClassLoader($prefix, $this->classLoader);
}
if (!empty($loader)) {
$this->classLoader->unregister();
$loader->register();
$this->classLoader = $loader;
}
}
} }
/** /**

View File

@ -18,7 +18,7 @@ class CommandLineOrUnsafeMethod implements RequestPolicyInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function check(Request $request) { public function check(Request $request) {
if ($this->isCli() || !$request->isMethodSafe()) { if ($this->isCli() || !$request->isMethodCacheable()) {
return static::DENY; return static::DENY;
} }
} }

View File

@ -93,7 +93,7 @@ class PlaceholderingRenderCache extends RenderCache {
*/ */
public function get(array $elements) { public function get(array $elements) {
// @todo remove this check when https://www.drupal.org/node/2367555 lands. // @todo remove this check when https://www.drupal.org/node/2367555 lands.
if (!$this->requestStack->getCurrentRequest()->isMethodSafe()) { if (!$this->requestStack->getCurrentRequest()->isMethodCacheable()) {
return FALSE; return FALSE;
} }
@ -127,7 +127,7 @@ class PlaceholderingRenderCache extends RenderCache {
$result = parent::set($elements, $pre_bubbling_elements); $result = parent::set($elements, $pre_bubbling_elements);
// @todo remove this check when https://www.drupal.org/node/2367555 lands. // @todo remove this check when https://www.drupal.org/node/2367555 lands.
if (!$this->requestStack->getCurrentRequest()->isMethodSafe()) { if (!$this->requestStack->getCurrentRequest()->isMethodCacheable()) {
return FALSE; return FALSE;
} }

View File

@ -61,9 +61,9 @@ class RenderCache implements RenderCacheInterface {
public function get(array $elements) { public function get(array $elements) {
// Form submissions rely on the form being built during the POST request, // Form submissions rely on the form being built during the POST request,
// and render caching of forms prevents this from happening. // and render caching of forms prevents this from happening.
// @todo remove the isMethodSafe() check when // @todo remove the isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands. // https://www.drupal.org/node/2367555 lands.
if (!$this->requestStack->getCurrentRequest()->isMethodSafe() || !$cid = $this->createCacheID($elements)) { if (!$this->requestStack->getCurrentRequest()->isMethodCacheable() || !$cid = $this->createCacheID($elements)) {
return FALSE; return FALSE;
} }
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render'; $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render';
@ -88,9 +88,9 @@ class RenderCache implements RenderCacheInterface {
public function set(array &$elements, array $pre_bubbling_elements) { public function set(array &$elements, array $pre_bubbling_elements) {
// Form submissions rely on the form being built during the POST request, // Form submissions rely on the form being built during the POST request,
// and render caching of forms prevents this from happening. // and render caching of forms prevents this from happening.
// @todo remove the isMethodSafe() check when // @todo remove the isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands. // https://www.drupal.org/node/2367555 lands.
if (!$this->requestStack->getCurrentRequest()->isMethodSafe() || !$cid = $this->createCacheID($elements)) { if (!$this->requestStack->getCurrentRequest()->isMethodCacheable() || !$cid = $this->createCacheID($elements)) {
return FALSE; return FALSE;
} }

View File

@ -338,9 +338,9 @@ class Renderer implements RendererInterface {
// If instructed to create a placeholder, and a #lazy_builder callback is // If instructed to create a placeholder, and a #lazy_builder callback is
// present (without such a callback, it would be impossible to replace the // present (without such a callback, it would be impossible to replace the
// placeholder), replace the current element with a placeholder. // placeholder), replace the current element with a placeholder.
// @todo remove the isMethodSafe() check when // @todo remove the isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands. // https://www.drupal.org/node/2367555 lands.
if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodSafe()) { if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodCacheable()) {
if (!isset($elements['#lazy_builder'])) { if (!isset($elements['#lazy_builder'])) {
throw new \LogicException('When #create_placeholder is set, a #lazy_builder callback must be present as well.'); throw new \LogicException('When #create_placeholder is set, a #lazy_builder callback must be present as well.');
} }

View File

@ -21,7 +21,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class ExecutionContext implements ExecutionContextInterface { class ExecutionContext implements ExecutionContextInterface {
/** /**
* @var \Symfony\Component\Validator\ValidatorInterface * @var \Symfony\Component\Validator\Validator\ValidatorInterface
*/ */
protected $validator; protected $validator;

View File

@ -108,7 +108,7 @@ class BigPipeStrategy implements PlaceholderStrategyInterface {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
// @todo remove this check when https://www.drupal.org/node/2367555 lands. // @todo remove this check when https://www.drupal.org/node/2367555 lands.
if (!$request->isMethodSafe()) { if (!$request->isMethodCacheable()) {
return []; return [];
} }

View File

@ -47,7 +47,7 @@ class BigPipeStrategyTest extends UnitTestCase {
$big_pipe_strategy = new BigPipeStrategy($session_configuration->reveal(), $request_stack->reveal(), $route_match->reveal()); $big_pipe_strategy = new BigPipeStrategy($session_configuration->reveal(), $request_stack->reveal(), $route_match->reveal());
$processed_placeholders = $big_pipe_strategy->processPlaceholders($placeholders); $processed_placeholders = $big_pipe_strategy->processPlaceholders($placeholders);
if ($request->isMethodSafe() && !$route_match_has_no_big_pipe_option && $request_has_session) { if ($request->isMethodCacheable() && !$route_match_has_no_big_pipe_option && $request_has_session) {
$this->assertSameSize($expected_big_pipe_placeholders, $processed_placeholders, 'BigPipe is able to deliver all placeholders.'); $this->assertSameSize($expected_big_pipe_placeholders, $processed_placeholders, 'BigPipe is able to deliver all placeholders.');
foreach (array_keys($placeholders) as $placeholder) { foreach (array_keys($placeholders) as $placeholder) {
$this->assertSame($expected_big_pipe_placeholders[$placeholder], $processed_placeholders[$placeholder], "Verifying how BigPipeStrategy handles the placeholder '$placeholder'"); $this->assertSame($expected_big_pipe_placeholders[$placeholder], $processed_placeholders[$placeholder], "Verifying how BigPipeStrategy handles the placeholder '$placeholder'");

View File

@ -76,7 +76,7 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
// Render the block. // Render the block.
// @todo The request stack manipulation won't be necessary once // @todo The request stack manipulation won't be necessary once
// https://www.drupal.org/node/2367555 is fixed and the // https://www.drupal.org/node/2367555 is fixed and the
// corresponding $request->isMethodSafe() checks are removed from // corresponding $request->isMethodCacheable() checks are removed from
// Drupal\Core\Render\Renderer. // Drupal\Core\Render\Renderer.
$request_stack = $this->container->get('request_stack'); $request_stack = $this->container->get('request_stack');
$request_stack->push(new Request()); $request_stack->push(new Request());

View File

@ -565,7 +565,7 @@ display:
decimal: . decimal: .
separator: ',' separator: ','
format_plural: true format_plural: true
format_plural_string: "1 place\x03@count places" format_plural_string: !!binary MSBwbGFjZQNAY291bnQgcGxhY2Vz
prefix: '' prefix: ''
suffix: '' suffix: ''
plugin_id: numeric plugin_id: numeric
@ -1007,7 +1007,7 @@ display:
decimal: . decimal: .
separator: ',' separator: ','
format_plural: false format_plural: false
format_plural_string: "1\x03@count" format_plural_string: !!binary MQNAY291bnQ=
prefix: '' prefix: ''
suffix: '' suffix: ''
plugin_id: numeric plugin_id: numeric

View File

@ -1080,7 +1080,7 @@ function node_query_node_access_alter(AlterableInterface $query) {
// context. // context.
$request = \Drupal::requestStack()->getCurrentRequest(); $request = \Drupal::requestStack()->getCurrentRequest();
$renderer = \Drupal::service('renderer'); $renderer = \Drupal::service('renderer');
if ($request->isMethodSafe() && $renderer->hasRenderContext()) { if ($request->isMethodCacheable() && $renderer->hasRenderContext()) {
$build = ['#cache' => ['contexts' => ['user.node_grants:' . $op]]]; $build = ['#cache' => ['contexts' => ['user.node_grants:' . $op]]];
$renderer->render($build); $renderer->render($build);
} }

View File

@ -96,7 +96,7 @@ class ResourceResponseSubscriber implements EventSubscriberInterface {
$route = $route_match->getRouteObject(); $route = $route_match->getRouteObject();
$acceptable_request_formats = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : []; $acceptable_request_formats = $route->hasRequirement('_format') ? explode('|', $route->getRequirement('_format')) : [];
$acceptable_content_type_formats = $route->hasRequirement('_content_type_format') ? explode('|', $route->getRequirement('_content_type_format')) : []; $acceptable_content_type_formats = $route->hasRequirement('_content_type_format') ? explode('|', $route->getRequirement('_content_type_format')) : [];
$acceptable_formats = $request->isMethodSafe() ? $acceptable_request_formats : $acceptable_content_type_formats; $acceptable_formats = $request->isMethodCacheable() ? $acceptable_request_formats : $acceptable_content_type_formats;
$requested_format = $request->getRequestFormat(); $requested_format = $request->getRequestFormat();
$content_type_format = $request->getContentType(); $content_type_format = $request->getContentType();

View File

@ -141,8 +141,8 @@ class CollectRoutesTest extends UnitTestCase {
$requirements_1 = $this->routes->get('test_1')->getRequirements(); $requirements_1 = $this->routes->get('test_1')->getRequirements();
$requirements_2 = $this->routes->get('view.test_view.page_1')->getRequirements(); $requirements_2 = $this->routes->get('view.test_view.page_1')->getRequirements();
$this->assertEquals(count($requirements_1), 0, 'First route has no requirement.'); $this->assertEquals(0, count($requirements_1), 'First route has no requirement.');
$this->assertEquals(count($requirements_2), 2, 'Views route with rest export had the format and method requirements added.'); $this->assertEquals(1, count($requirements_2), 'Views route with rest export had the format requirement added.');
// Check auth options. // Check auth options.
$auth = $this->routes->get('view.test_view.page_1')->getOption('_auth'); $auth = $this->routes->get('view.test_view.page_1')->getOption('_auth');

View File

@ -79,11 +79,6 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
* @dataProvider providerTestResponseFormat * @dataProvider providerTestResponseFormat
*/ */
public function testResponseFormat($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) { public function testResponseFormat($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) {
$parameters = [];
if ($request_format !== FALSE) {
$parameters['_format'] = $request_format;
}
foreach ($request_headers as $key => $value) { foreach ($request_headers as $key => $value) {
unset($request_headers[$key]); unset($request_headers[$key]);
$key = strtoupper(str_replace('-', '_', $key)); $key = strtoupper(str_replace('-', '_', $key));
@ -91,8 +86,13 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
} }
foreach ($methods as $method) { foreach ($methods as $method) {
$request = Request::create('/rest/test', $method, $parameters, [], [], $request_headers, $request_body); $request = Request::create('/rest/test', $method, [], [], [], $request_headers, $request_body);
$route_requirement_key_format = $request->isMethodSafe() ? '_format' : '_content_type_format'; // \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care
// of this so we'll hard code it here.
if ($request_format) {
$request->setRequestFormat($request_format);
}
$route_requirement_key_format = $request->isMethodCacheable() ? '_format' : '_content_type_format';
$route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $this->randomMachineName()], [$route_requirement_key_format => implode('|', $supported_formats)])); $route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $this->randomMachineName()], [$route_requirement_key_format => implode('|', $supported_formats)]));
$resource_response_subscriber = new ResourceResponseSubscriber( $resource_response_subscriber = new ResourceResponseSubscriber(
@ -116,11 +116,6 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
public function testOnResponseWithCacheableResponse($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) { public function testOnResponseWithCacheableResponse($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) {
$rest_config_name = $this->randomMachineName(); $rest_config_name = $this->randomMachineName();
$parameters = [];
if ($request_format !== FALSE) {
$parameters['_format'] = $request_format;
}
foreach ($request_headers as $key => $value) { foreach ($request_headers as $key => $value) {
unset($request_headers[$key]); unset($request_headers[$key]);
$key = strtoupper(str_replace('-', '_', $key)); $key = strtoupper(str_replace('-', '_', $key));
@ -128,8 +123,13 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
} }
foreach ($methods as $method) { foreach ($methods as $method) {
$request = Request::create('/rest/test', $method, $parameters, [], [], $request_headers, $request_body); $request = Request::create('/rest/test', $method, [], [], [], $request_headers, $request_body);
$route_requirement_key_format = $request->isMethodSafe() ? '_format' : '_content_type_format'; // \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care
// of this so we'll hard code it here.
if ($request_format) {
$request->setRequestFormat($request_format);
}
$route_requirement_key_format = $request->isMethodCacheable() ? '_format' : '_content_type_format';
$route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $rest_config_name], [$route_requirement_key_format => implode('|', $supported_formats)])); $route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $rest_config_name], [$route_requirement_key_format => implode('|', $supported_formats)]));
// The RequestHandler must return a ResourceResponseInterface object. // The RequestHandler must return a ResourceResponseInterface object.
@ -166,11 +166,6 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
public function testOnResponseWithUncacheableResponse($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) { public function testOnResponseWithUncacheableResponse($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_format, $expected_response_content_type, $expected_response_content) {
$rest_config_name = $this->randomMachineName(); $rest_config_name = $this->randomMachineName();
$parameters = [];
if ($request_format !== FALSE) {
$parameters['_format'] = $request_format;
}
foreach ($request_headers as $key => $value) { foreach ($request_headers as $key => $value) {
unset($request_headers[$key]); unset($request_headers[$key]);
$key = strtoupper(str_replace('-', '_', $key)); $key = strtoupper(str_replace('-', '_', $key));
@ -178,8 +173,13 @@ class ResourceResponseSubscriberTest extends UnitTestCase {
} }
foreach ($methods as $method) { foreach ($methods as $method) {
$request = Request::create('/rest/test', $method, $parameters, [], [], $request_headers, $request_body); $request = Request::create('/rest/test', $method, [], [], [], $request_headers, $request_body);
$route_requirement_key_format = $request->isMethodSafe() ? '_format' : '_content_type_format'; // \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care
// of this so we'll hard code it here.
if ($request_format) {
$request->setRequestFormat($request_format);
}
$route_requirement_key_format = $request->isMethodCacheable() ? '_format' : '_content_type_format';
$route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $rest_config_name], [$route_requirement_key_format => implode('|', $supported_formats)])); $route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $rest_config_name], [$route_requirement_key_format => implode('|', $supported_formats)]));
// The RequestHandler must return a ResourceResponseInterface object. // The RequestHandler must return a ResourceResponseInterface object.

View File

@ -86,7 +86,7 @@ class FormTestStorageForm extends FormBase {
// that issue. // that issue.
if ($this->getRequest()->get('immutable')) { if ($this->getRequest()->get('immutable')) {
$form_state->addBuildInfo('immutable', TRUE); $form_state->addBuildInfo('immutable', TRUE);
if ($this->getRequest()->get('cache') && $this->getRequest()->isMethodSafe()) { if ($this->getRequest()->get('cache') && $this->getRequest()->isMethodCacheable()) {
$form_state->setRequestMethod('FAKE'); $form_state->setRequestMethod('FAKE');
$form_state->setCached(); $form_state->setCached();
} }

View File

@ -17,7 +17,8 @@ class ThemeTestSubscriber implements EventSubscriberInterface {
/** /**
* The used container. * The used container.
* *
* @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface * @todo This variable is never initialzed, so we don't know what it is.
* See https://www.drupal.org/node/2721315
*/ */
protected $container; protected $container;

View File

@ -662,47 +662,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.'); $this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.');
} }
/**
* Tests that unsupported methods throw an Exception.
*
* @covers ::enterScope
* @covers ::leaveScope
* @covers ::addScope
* @covers ::hasScope
* @covers ::isScopeActive
*
* @expectedException \BadMethodCallException
*
* @dataProvider scopeExceptionTestProvider
*/
public function testScopeFunctionsWithException($method, $argument) {
$callable = array(
$this->container,
$method,
);
$callable($argument);
}
/**
* Data provider for scopeExceptionTestProvider().
*
* @return array[]
* Returns per data set an array with:
* - method name to call
* - argument to pass
*/
public function scopeExceptionTestProvider() {
$scope = $this->prophesize('\Symfony\Component\DependencyInjection\ScopeInterface')->reveal();
return array(
array('enterScope', 'test_scope'),
array('leaveScope', 'test_scope'),
array('hasScope', 'test_scope'),
array('isScopeActive', 'test_scope'),
array('addScope', $scope),
);
}
/** /**
* Tests that Container::getServiceIds() works properly. * Tests that Container::getServiceIds() works properly.
* *

View File

@ -245,7 +245,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
'arguments_count' => 0, 'arguments_count' => 0,
'properties' => array(), 'properties' => array(),
'calls' => array(), 'calls' => array(),
'scope' => ContainerInterface::SCOPE_CONTAINER,
'shared' => TRUE, 'shared' => TRUE,
'factory' => FALSE, 'factory' => FALSE,
'configurator' => FALSE, 'configurator' => FALSE,
@ -357,11 +356,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
'calls' => $calls, 'calls' => $calls,
) + $base_service_definition; ) + $base_service_definition;
$service_definitions[] = array(
'scope' => ContainerInterface::SCOPE_PROTOTYPE,
'shared' => FALSE,
) + $base_service_definition;
$service_definitions[] = array( $service_definitions[] = array(
'shared' => FALSE, 'shared' => FALSE,
) + $base_service_definition; ) + $base_service_definition;
@ -404,7 +398,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$definition->getArguments()->willReturn($service_definition['arguments']); $definition->getArguments()->willReturn($service_definition['arguments']);
$definition->getProperties()->willReturn($service_definition['properties']); $definition->getProperties()->willReturn($service_definition['properties']);
$definition->getMethodCalls()->willReturn($service_definition['calls']); $definition->getMethodCalls()->willReturn($service_definition['calls']);
$definition->getScope()->willReturn($service_definition['scope']);
$definition->isShared()->willReturn($service_definition['shared']); $definition->isShared()->willReturn($service_definition['shared']);
$definition->getDecoratedService()->willReturn(NULL); $definition->getDecoratedService()->willReturn(NULL);
$definition->getFactory()->willReturn($service_definition['factory']); $definition->getFactory()->willReturn($service_definition['factory']);
@ -437,9 +430,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
} }
} }
// Remove any remaining scope.
unset($filtered_service_definition['scope']);
if (isset($filtered_service_definition['public']) && $filtered_service_definition['public'] === FALSE) { if (isset($filtered_service_definition['public']) && $filtered_service_definition['public'] === FALSE) {
$services_provided[] = array( $services_provided[] = array(
array('foo_service' => $definition->reveal()), array('foo_service' => $definition->reveal()),
@ -477,22 +467,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
); );
} }
/**
* Tests that the correct InvalidArgumentException is thrown for getScope().
*
* @covers ::getServiceDefinition
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetServiceDefinitionWithInvalidScope() {
$bar_definition = new Definition('\stdClass');
$bar_definition->setScope('foo_scope');
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->dumper->getArray();
}
/** /**
* Tests that references to aliases work correctly. * Tests that references to aliases work correctly.
* *

View File

@ -6,9 +6,10 @@ namespace Drupal\Tests\Component\EventDispatcher;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Tests\CallableClass; use Symfony\Component\EventDispatcher\Tests\CallableClass;
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
use Symfony\Component\EventDispatcher\Tests\ContainerAwareEventDispatcherTest as SymfonyContainerAwareEventDispatcherTest; use Symfony\Component\EventDispatcher\Tests\ContainerAwareEventDispatcherTest as SymfonyContainerAwareEventDispatcherTest;
use Symfony\Component\EventDispatcher\Tests\TestEventListener;
/** /**
* Unit tests for the ContainerAwareEventDispatcher. * Unit tests for the ContainerAwareEventDispatcher.
@ -37,7 +38,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
// When passing in callables exclusively as listeners into the event // When passing in callables exclusively as listeners into the event
// dispatcher constructor, the event dispatcher must not attempt to // dispatcher constructor, the event dispatcher must not attempt to
// resolve any services. // resolve any services.
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface'); $container = $this->getMock(ContainerInterface::class);
$container->expects($this->never())->method($this->anything()); $container->expects($this->never())->method($this->anything());
$firstListener = new CallableClass(); $firstListener = new CallableClass();
@ -72,7 +73,7 @@ class ContainerAwareEventDispatcherTest extends SymfonyContainerAwareEventDispat
// When passing in callables exclusively as listeners into the event // When passing in callables exclusively as listeners into the event
// dispatcher constructor, the event dispatcher must not attempt to // dispatcher constructor, the event dispatcher must not attempt to
// resolve any services. // resolve any services.
$container = $this->getMock('Symfony\Component\DependencyInjection\IntrospectableContainerInterface'); $container = $this->getMock(ContainerInterface::class);
$container->expects($this->never())->method($this->anything()); $container->expects($this->never())->method($this->anything());
$firstListener = new CallableClass(); $firstListener = new CallableClass();

View File

@ -10,6 +10,7 @@ use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface; use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/** /**
* @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase * @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase
@ -321,7 +322,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
* @covers ::validate * @covers ::validate
*/ */
public function testValidate() { public function testValidate() {
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); $validator = $this->getMock(ValidatorInterface::class);
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
$empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList') $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
->setMethods(NULL) ->setMethods(NULL)
@ -357,7 +358,7 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
* @expectedExceptionMessage Entity validation was skipped. * @expectedExceptionMessage Entity validation was skipped.
*/ */
public function testRequiredValidation() { public function testRequiredValidation() {
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface'); $validator = $this->getMock(ValidatorInterface::class);
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */ /** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit_Framework_MockObject_MockObject $empty_violation_list */
$empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList') $empty_violation_list = $this->getMockBuilder('\Symfony\Component\Validator\ConstraintViolationList')
->setMethods(NULL) ->setMethods(NULL)

View File

@ -25,7 +25,10 @@ class DefaultExceptionSubscriberTest extends UnitTestCase {
// Format 'bananas' requested, yet only 'json' allowed. // Format 'bananas' requested, yet only 'json' allowed.
$kernel = $this->prophesize(HttpKernelInterface::class); $kernel = $this->prophesize(HttpKernelInterface::class);
$request = Request::create('/test?_format=bananas'); $request = Request::create('/test');
// \Drupal\Core\StackMiddleware\NegotiationMiddleware normally takes care
// of this so we'll hard code it here.
$request->setRequestFormat('bananas');
$e = new MethodNotAllowedHttpException(['json'], 'test message'); $e = new MethodNotAllowedHttpException(['json'], 'test message');
$event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $e); $event = new GetResponseForExceptionEvent($kernel->reveal(), $request, 'GET', $e);
$subscriber = new DefaultExceptionSubscriber($config_factory); $subscriber = new DefaultExceptionSubscriber($config_factory);