summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib/Drupal')
-rw-r--r--core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php13
-rw-r--r--core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php63
-rw-r--r--core/lib/Drupal/Component/Serialization/YamlSymfony.php2
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php27
-rw-r--r--core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php11
-rw-r--r--core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php7
-rw-r--r--core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php10
-rw-r--r--core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php9
8 files changed, 104 insertions, 38 deletions
diff --git a/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php b/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
index 11768d0..dfd2a43 100644
--- a/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
+++ b/core/lib/Drupal/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php
@@ -65,7 +65,7 @@ class OptimizedPhpArrayDumper extends Dumper {
$definition['aliases'] = $this->getAliases();
$definition['parameters'] = $this->getParameters();
$definition['services'] = $this->getServiceDefinitions();
- $definition['frozen'] = $this->container->isFrozen();
+ $definition['frozen'] = $this->container->isCompiled();
$definition['machine_format'] = $this->supportsMachineFormat();
return $definition;
}
@@ -103,8 +103,8 @@ class OptimizedPhpArrayDumper extends Dumper {
}
$parameters = $this->container->getParameterBag()->all();
- $is_frozen = $this->container->isFrozen();
- return $this->prepareParameters($parameters, $is_frozen);
+ $is_compiled = $this->container->isCompiled();
+ return $this->prepareParameters($parameters, $is_compiled);
}
/**
@@ -309,10 +309,10 @@ class OptimizedPhpArrayDumper extends Dumper {
}
}
else {
- if (is_object($value)) {
+ $code[$key] = $this->dumpValue($value);
+ if (is_object($code[$key])) {
$resolve = TRUE;
}
- $code[$key] = $this->dumpValue($value);
}
}
@@ -403,6 +403,9 @@ class OptimizedPhpArrayDumper extends Dumper {
elseif ($value instanceof Parameter) {
return $this->getParameterCall((string) $value);
}
+ elseif (is_string($value) && preg_match('/^\%(.*)\%$/', $value, $matches)) {
+ return $this->getParameterCall($matches[1]);
+ }
elseif ($value instanceof Expression) {
throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
diff --git a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
index a23f333..1fd808c 100644
--- a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
+++ b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
@@ -104,8 +104,11 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
if (!isset($definition['callable'])) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
+ if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
+ $definition['callable'][0] = $definition['callable'][0]();
+ }
- $definition['callable']($event, $event_name, $this);
+ call_user_func($definition['callable'], $event, $event_name, $this);
if ($event->isPropagationStopped()) {
return $event;
}
@@ -144,6 +147,9 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
if (!isset($definition['callable'])) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
+ if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
+ $definition['callable'][0] = $definition['callable'][0]();
+ }
$result[] = $definition['callable'];
}
@@ -156,27 +162,29 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
/**
* {@inheritdoc}
*/
- public function getListenerPriority($eventName, $listener) {
- // Parts copied from \Symfony\Component\EventDispatcher, that's why you see
- // a yoda condition here.
- if (!isset($this->listeners[$eventName])) {
+ public function getListenerPriority($event_name, $listener) {
+ if (!isset($this->listeners[$event_name])) {
return;
}
- foreach ($this->listeners[$eventName] as $priority => $listeners) {
- if (FALSE !== ($key = array_search(['callable' => $listener], $listeners, TRUE))) {
- return $priority;
- }
+ if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
+ $listener[0] = $listener[0]();
}
// Resolve service definitions if the listener has not been found so far.
- foreach ($this->listeners[$eventName] as $priority => &$definitions) {
+ foreach ($this->listeners[$event_name] as $priority => &$definitions) {
foreach ($definitions as $key => &$definition) {
if (!isset($definition['callable'])) {
// Once the callable is retrieved we keep it for subsequent method
// invocations on this class.
- $definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
- if ($definition['callable'] === $listener) {
- return $priority;
- }
+ $definition['callable'] = [
+ $this->container->get($definition['service'][0]),
+ $definition['service'][1],
+ ];
+ }
+ if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
+ $definition['callable'][0] = $definition['callable'][0]();
+ }
+ if ($definition['callable'] === $listener) {
+ return $priority;
}
}
}
@@ -186,7 +194,17 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
* {@inheritdoc}
*/
public function hasListeners($event_name = NULL) {
- return (bool) count($this->getListeners($event_name));
+ if ($event_name !== NULL) {
+ return !empty($this->listeners[$event_name]);
+ }
+
+ foreach ($this->listeners as $event_listeners) {
+ if ($event_listeners) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
/**
@@ -214,10 +232,23 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
+ if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure && !$listener instanceof \Closure) {
+ $definition['callable'][0] = $definition['callable'][0]();
+ }
+
+ if (is_array($definition['callable']) && isset($definition['callable'][0]) && !$definition['callable'][0] instanceof \Closure && is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
+ $listener[0] = $listener[0]();
+ }
if ($definition['callable'] === $listener) {
- unset($this->listeners[$event_name][$priority][$key]);
+ unset($definitions[$key]);
}
}
+ if ($definitions) {
+ $this->listeners[$event_name][$priority] = $definitions;
+ }
+ else {
+ unset($this->listeners[$event_name][$priority]);
+ }
}
}
diff --git a/core/lib/Drupal/Component/Serialization/YamlSymfony.php b/core/lib/Drupal/Component/Serialization/YamlSymfony.php
index d35e09c..efe3039 100644
--- a/core/lib/Drupal/Component/Serialization/YamlSymfony.php
+++ b/core/lib/Drupal/Component/Serialization/YamlSymfony.php
@@ -34,7 +34,7 @@ class YamlSymfony implements SerializationInterface {
$yaml = new Parser();
// Make sure we have a single trailing newline. A very simple config like
// 'foo: bar' with no newline will fail to parse otherwise.
- return $yaml->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
+ return $yaml->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::PARSE_KEYS_AS_STRINGS);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index e0becc7..00b6f76 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -46,9 +46,12 @@ class ContainerBuilder extends SymfonyContainerBuilder {
}
/**
- * {@inheritdoc}
+ * A 1to1 copy of parent::shareService.
+ *
+ * @todo https://www.drupal.org/project/drupal/issues/2937010 Since Symfony
+ * 3.4 this is not a 1to1 copy.
*/
- protected function shareService(Definition $definition, $service, $id)
+ protected function shareService(Definition $definition, $service, $id, array &$inlineServices)
{
if ($definition->isShared()) {
$this->services[$lowerId = strtolower($id)] = $service;
@@ -85,7 +88,20 @@ class ContainerBuilder extends SymfonyContainerBuilder {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
}
- return parent::register($id, $class);
+ $definition = parent::register($id, $class);
+ // As of Symfony 3.4 all services are private by default.
+ $definition->setPublic(TRUE);
+ return $definition;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setAlias($alias, $id) {
+ $alias = parent::setAlias($alias, $id);
+ // As of Symfony 3.4 all aliases are private by default.
+ $alias->setPublic(TRUE);
+ return $alias;
}
/**
@@ -100,8 +116,11 @@ class ContainerBuilder extends SymfonyContainerBuilder {
/**
* A 1to1 copy of parent::callMethod.
+ *
+ * @todo https://www.drupal.org/project/drupal/issues/2937010 Since Symfony
+ * 3.4 this is not a 1to1 copy.
*/
- protected function callMethod($service, $call) {
+ protected function callMethod($service, $call, array &$inlineServices = array()) {
$services = self::getServiceConditionals($call[1]);
foreach ($services as $s) {
diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
index d999450..55687bb 100644
--- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
+++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
@@ -8,7 +8,7 @@ use Drupal\Core\Serialization\Yaml;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
-use Symfony\Component\DependencyInjection\DefinitionDecorator;
+use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -155,9 +155,11 @@ class YamlFileLoader
}
if (isset($service['parent'])) {
- $definition = new DefinitionDecorator($service['parent']);
+ $definition = new ChildDefinition($service['parent']);
} else {
$definition = new Definition();
+ // As of Symfony 3.4 all services are private by default.
+ $definition->setPublic(TRUE);
}
if (isset($service['class'])) {
@@ -329,7 +331,10 @@ class YamlFileLoader
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
}
- return $this->validate(Yaml::decode(file_get_contents($file)), $file);
+ // @todo Remove preg_replace() once
+ // https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
+ $content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', file_get_contents($file));
+ return $this->validate(Yaml::decode($content), $file);
}
/**
diff --git a/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php b/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php
index 6c9c178..0e49c5b 100644
--- a/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php
+++ b/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php
@@ -76,10 +76,10 @@ class FormAjaxSubscriber implements EventSubscriberInterface {
// the configured upload limit.
if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
$this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
- $response = new AjaxResponse();
+ $response = new AjaxResponse(NULL, 200);
$status_messages = ['#type' => 'status_messages'];
$response->addCommand(new PrependCommand(NULL, $status_messages));
- $response->headers->set('X-Status-Code', 200);
+ $event->allowCustomResponseCode();
$event->setResponse($response);
return;
}
@@ -99,7 +99,8 @@ class FormAjaxSubscriber implements EventSubscriberInterface {
// Since this response is being set in place of an exception, explicitly
// mark this as a 200 status.
- $response->headers->set('X-Status-Code', 200);
+ $response->setStatusCode(200);
+ $event->allowCustomResponseCode();
$event->setResponse($response);
}
catch (\Exception $e) {
diff --git a/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php b/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
index e3e4895..cf4cd89 100644
--- a/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
+++ b/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
@@ -59,23 +59,23 @@ class ReverseProxyMiddleware implements HttpKernelInterface {
// Initialize proxy settings.
if ($settings->get('reverse_proxy', FALSE)) {
$ip_header = $settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
- $request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $ip_header);
+ $request::setTrustedHeaderName($request::HEADER_X_FORWARDED_FOR, $ip_header);
$proto_header = $settings->get('reverse_proxy_proto_header', 'X_FORWARDED_PROTO');
- $request::setTrustedHeaderName($request::HEADER_CLIENT_PROTO, $proto_header);
+ $request::setTrustedHeaderName($request::HEADER_X_FORWARDED_PROTO, $proto_header);
$host_header = $settings->get('reverse_proxy_host_header', 'X_FORWARDED_HOST');
- $request::setTrustedHeaderName($request::HEADER_CLIENT_HOST, $host_header);
+ $request::setTrustedHeaderName($request::HEADER_X_FORWARDED_HOST, $host_header);
$port_header = $settings->get('reverse_proxy_port_header', 'X_FORWARDED_PORT');
- $request::setTrustedHeaderName($request::HEADER_CLIENT_PORT, $port_header);
+ $request::setTrustedHeaderName($request::HEADER_X_FORWARDED_PORT, $port_header);
$forwarded_header = $settings->get('reverse_proxy_forwarded_header', 'FORWARDED');
$request::setTrustedHeaderName($request::HEADER_FORWARDED, $forwarded_header);
$proxies = $settings->get('reverse_proxy_addresses', []);
if (count($proxies) > 0) {
- $request::setTrustedProxies($proxies);
+ $request::setTrustedProxies($proxies, Request::HEADER_X_FORWARDED_ALL | Request::HEADER_FORWARDED);
}
}
}
diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
index 3165815..03990d8 100644
--- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
+++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
@@ -120,6 +120,9 @@ trait FunctionalTestSetupTrait {
// Add a listener to validate configuration schema on save.
$yaml = new SymfonyYaml();
$content = file_get_contents($directory . '/services.yml');
+ // @todo Remove preg_replace() once
+ // https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
+ $content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', $content);
$services = $yaml->parse($content);
$services['services']['simpletest.config_schema_checker'] = [
'class' => ConfigSchemaChecker::class,
@@ -165,7 +168,11 @@ trait FunctionalTestSetupTrait {
$filename = $this->siteDirectory . '/services.yml';
chmod($filename, 0666);
- $services = Yaml::decode(file_get_contents($filename));
+ // @todo Remove preg_replace() once
+ // https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
+ $content = file_get_contents($filename);
+ $content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', $content);
+ $services = Yaml::decode($content);
$services['parameters'][$name] = $value;
file_put_contents($filename, Yaml::encode($services));