Skip to content

Commit 956708b

Browse files
Merge branch '4.3' into 4.4
* 4.3: [HttpClient] Fix a bug preventing Server Pushes to be handled properly [HttpClient] fix support for 103 Early Hints and other informational status codes [DI] fix failure [Validator] Add ConstraintValidator::formatValue() tests [HttpClient] improve handling of HTTP/2 PUSH Fix #33427 [Validator] Only handle numeric values in DivisibleBy [Validator] Sync string to date behavior and throw a better exception Check phpunit configuration for listeners [DI] fix support for "!tagged_locator foo"
2 parents 85113f1 + be579a7 commit 956708b

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

Loader/Configurator/ContainerConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function tagged_iterator(string $tag, string $indexAttribute = null, string $def
136136
/**
137137
* Creates a service locator by tag name.
138138
*/
139-
function tagged_locator(string $tag, string $indexAttribute, string $defaultIndexMethod = null): ServiceLocatorArgument
139+
function tagged_locator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null): ServiceLocatorArgument
140140
{
141141
return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true));
142142
}

Loader/YamlFileLoader.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -719,25 +719,23 @@ private function resolveServices($value, string $file, bool $isParameter = false
719719

720720
$forLocator = 'tagged_locator' === $value->getTag();
721721

722-
if (\is_string($argument) && $argument) {
723-
return new TaggedIteratorArgument($argument, null, null, $forLocator);
724-
}
725-
726722
if (\is_array($argument) && isset($argument['tag']) && $argument['tag']) {
727723
if ($diff = array_diff(array_keys($argument), ['tag', 'index_by', 'default_index_method'])) {
728724
throw new InvalidArgumentException(sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "tag", "index_by" and "default_index_method".', $value->getTag(), implode('"", "', $diff)));
729725
}
730726

731727
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator);
728+
} elseif (\is_string($argument) && $argument) {
729+
$argument = new TaggedIteratorArgument($argument, null, null, $forLocator);
730+
} else {
731+
throw new InvalidArgumentException(sprintf('"!%s" tags only accept a non empty string or an array with a key "tag" in "%s".', $value->getTag(), $file));
732+
}
732733

733-
if ($forLocator) {
734-
$argument = new ServiceLocatorArgument($argument);
735-
}
736-
737-
return $argument;
734+
if ($forLocator) {
735+
$argument = new ServiceLocatorArgument($argument);
738736
}
739737

740-
throw new InvalidArgumentException(sprintf('"!%s" tags only accept a non empty string or an array with a key "tag" in "%s".', $value->getTag(), $file));
738+
return $argument;
741739
}
742740
if ('service' === $value->getTag()) {
743741
if ($isParameter) {

Tests/Dumper/YamlDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function testTaggedArguments()
104104
$container->register('foo_service', 'Foo')->addTag('foo');
105105
$container->register('foo_service_tagged_iterator', 'Bar')->addArgument($taggedIterator);
106106
$container->register('foo_service_tagged_locator', 'Bar')->addArgument(new ServiceLocatorArgument($taggedIterator));
107+
$container->register('bar_service_tagged_locator', 'Bar')->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo')));
107108

108109
$dumper = new YamlDumper($container);
109110
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_with_tagged_argument.yml', $dumper->dump());

Tests/Fixtures/yaml/services_with_tagged_argument.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ services:
1414
foo_service_tagged_locator:
1515
class: Bar
1616
arguments: [!tagged_locator { tag: foo, index_by: barfoo, default_index_method: foobar }]
17+
bar_service_tagged_locator:
18+
class: Bar
19+
arguments: [!tagged_locator foo]
1720
Psr\Container\ContainerInterface:
1821
alias: service_container
1922
public: false

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ public function testTaggedArgumentsWithIndex()
311311

312312
$taggedIterator = new TaggedIteratorArgument('foo', 'barfoo', 'foobar', true);
313313
$this->assertEquals(new ServiceLocatorArgument($taggedIterator), $container->getDefinition('foo_service_tagged_locator')->getArgument(0));
314+
315+
if (is_subclass_of('Symfony\Component\Yaml\Exception\ExceptionInterface', 'Throwable')) {
316+
// this test is not compatible with Yaml v3
317+
$taggedIterator = new TaggedIteratorArgument('foo', null, null, true);
318+
$this->assertEquals(new ServiceLocatorArgument($taggedIterator), $container->getDefinition('bar_service_tagged_locator')->getArgument(0));
319+
}
314320
}
315321

316322
public function testNameOnlyTagsAreAllowedAsString()

0 commit comments

Comments
 (0)