Skip to content

Commit 9198b9d

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] remove messenger cache if not enabled [HttpClient] Fix strict parsing of response status codes [DI] Suggest typed argument when binding fails with untyped argument
2 parents e21b153 + 477e843 commit 9198b9d

File tree

9 files changed

+66
-4
lines changed

9 files changed

+66
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public function load(array $configs, ContainerBuilder $container)
313313
$container->removeDefinition('console.command.messenger_failed_messages_retry');
314314
$container->removeDefinition('console.command.messenger_failed_messages_show');
315315
$container->removeDefinition('console.command.messenger_failed_messages_remove');
316+
$container->removeDefinition('cache.messenger.restart_workers_signal');
316317
}
317318

318319
if ($this->httpClientConfigEnabled = $this->isConfigEnabled($container, $config['http_client'])) {

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
426426
</xsd:sequence>
427427
<xsd:attribute name="default-bus" type="xsd:string" />
428+
<xsd:attribute name="enabled" type="xsd:boolean" />
428429
</xsd:complexType>
429430

430431
<xsd:complexType name="messenger_serializer">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'messenger' => false,
5+
]);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:messenger enabled="false" />
10+
</framework:config>
11+
</container>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
framework:
2+
messenger: false

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,23 @@ public function testWebLink()
668668
$this->assertTrue($container->hasDefinition('web_link.add_link_header_listener'));
669669
}
670670

671+
public function testMessengerServicesRemovedWhenDisabled()
672+
{
673+
$container = $this->createContainerFromFile('messenger_disabled');
674+
$this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
675+
$this->assertFalse($container->hasDefinition('console.command.messenger_debug'));
676+
$this->assertFalse($container->hasDefinition('console.command.messenger_stop_workers'));
677+
$this->assertFalse($container->hasDefinition('console.command.messenger_setup_transports'));
678+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_retry'));
679+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_show'));
680+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_remove'));
681+
$this->assertFalse($container->hasDefinition('cache.messenger.restart_workers_signal'));
682+
}
683+
671684
public function testMessenger()
672685
{
673686
$container = $this->createContainerFromFile('messenger');
687+
$this->assertTrue($container->hasDefinition('console.command.messenger_consume_messages'));
674688
$this->assertTrue($container->hasAlias('message_bus'));
675689
$this->assertTrue($container->getAlias('message_bus')->isPublic());
676690
$this->assertTrue($container->hasAlias('messenger.default_bus'));

src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ protected function processValue($value, $isRoot = false)
114114
return parent::processValue($value, $isRoot);
115115
}
116116

117+
$bindingNames = [];
118+
117119
foreach ($bindings as $key => $binding) {
118120
list($bindingValue, $bindingId, $used, $bindingType, $file) = $binding->getValues();
119121
if ($used) {
@@ -123,7 +125,11 @@ protected function processValue($value, $isRoot = false)
123125
$this->unusedBindings[$bindingId] = [$key, $this->currentId, $bindingType, $file];
124126
}
125127

126-
if (preg_match('/^(?:(?:array|bool|float|int|string) )?\$/', $key)) {
128+
if (preg_match('/^(?:(?:array|bool|float|int|string|([^ $]++)) )\$/', $key, $m)) {
129+
$bindingNames[substr($key, \strlen($m[0]))] = $binding;
130+
}
131+
132+
if (!isset($m[1])) {
127133
continue;
128134
}
129135

@@ -184,11 +190,17 @@ protected function processValue($value, $isRoot = false)
184190
continue;
185191
}
186192

187-
if (!$typeHint || '\\' !== $typeHint[0] || !isset($bindings[$typeHint = substr($typeHint, 1)])) {
193+
if ($typeHint && '\\' === $typeHint[0] && isset($bindings[$typeHint = substr($typeHint, 1)])) {
194+
$arguments[$key] = $this->getBindingValue($bindings[$typeHint]);
195+
188196
continue;
189197
}
190198

191-
$arguments[$key] = $this->getBindingValue($bindings[$typeHint]);
199+
if (isset($bindingNames[$parameter->name])) {
200+
$bindingKey = array_search($binding, $bindings, true);
201+
$argumentType = substr($bindingKey, 0, strpos($bindingKey, ' '));
202+
$this->errorMessages[] = sprintf('Did you forget to add the type "%s" to argument "$%s" of method "%s::%s()"?', $argumentType, $parameter->name, $reflectionMethod->class, $reflectionMethod->name);
203+
}
192204
}
193205

194206
if ($arguments !== $call[1]) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
2121
use Symfony\Component\DependencyInjection\ContainerBuilder;
2222
use Symfony\Component\DependencyInjection\Definition;
23+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2324
use Symfony\Component\DependencyInjection\Reference;
2425
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2526
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
@@ -169,4 +170,19 @@ public function testSyntheticServiceWithBind()
169170

170171
$this->assertSame([1 => 'bar'], $container->getDefinition(NamedArgumentsDummy::class)->getArguments());
171172
}
173+
174+
public function testEmptyBindingTypehint()
175+
{
176+
$this->expectException(InvalidArgumentException::class);
177+
$this->expectExceptionMessage('Did you forget to add the type "string" to argument "$apiKey" of method "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy::__construct()"?');
178+
179+
$container = new ContainerBuilder();
180+
$bindings = [
181+
'string $apiKey' => new BoundArgument('foo'),
182+
];
183+
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
184+
$definition->setBindings($bindings);
185+
$pass = new ResolveBindingsPass();
186+
$pass->process($container);
187+
}
172188
}

src/Symfony/Component/HttpClient/Response/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private static function initialize(self $response): void
253253
private static function addResponseHeaders(array $responseHeaders, array &$info, array &$headers, string &$debug = ''): void
254254
{
255255
foreach ($responseHeaders as $h) {
256-
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([12345]\d\d) .*#', $h, $m)) {
256+
if (11 <= \strlen($h) && '/' === $h[4] && preg_match('#^HTTP/\d+(?:\.\d+)? ([12345]\d\d)(?: |$)#', $h, $m)) {
257257
if ($headers) {
258258
$debug .= "< \r\n";
259259
$headers = [];

0 commit comments

Comments
 (0)