8000 Fallback to defaultIndexMethod if resolved parameter value is falsy · symfony/symfony@c3653e4 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit c3653e4

Browse files
committed
Fallback to defaultIndexMethod if resolved parameter value is falsy
1 parent 6d567d2 commit c3653e4

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM composer:latest
2+
3+
RUN apk add --no-cache \
4+
$PHPIZE_DEPS \
5+
acl \
6+
coreutils \
7+
curl \
8+
cyrus-sasl-dev \
9+
fcgi \
10+
file \
11+
g++ \
12+
git \
13+
icu-dev \
14+
icu-data-full \
15+
libintl \
16+
libpng-dev \
17+
libsodium-dev \
18+
libxml2-dev \
19+
libxslt-dev \
20+
libzip-dev \
21+
musl-locales \
22+
openssl-dev \
23+
wget \
24+
zlib-dev
25+
26+
RUN docker-php-ext-install \
27+
bcmath \
28+
gd \
29+
intl \
30+
opcache \
31+
pdo \
32+
pdo_mysql \
33+
soap \
34+
sodium \
35+
zip \
36+
xsl
37+
38+
COPY .git /var/www/html/.git
39+
COPY src /var/www/html/src
40+
COPY composer.json /var/www/html/composer.json
41+
COPY phpunit /var/www/html/.git
42+
COPY phpunit.xml.dist /var/www/html/phpunit.xml.dist
43+
44+
WORKDIR /var/www/html
45+
46+
RUN git config --global --add safe.directory /var/www/html
47+
RUN git status && COMPOSER_ALLOW_SUPERUSER=1 composer install
48+
49+
COPY phpunit* /var/www/html
50+
51+
RUN chmod +x ./phpunit
52+
53+
CMD ["./phpunit"]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
8282

8383
if (null !== $indexAttribute && isset($attribute[$indexAttribute])) {
8484
$index = $attribute[$indexAttribute];
85-
$index = $container->getParameterBag()->resolveValue($index) ?: $index;
86-
} elseif (null === $defaultIndex && $defaultPriorityMethod && $class) {
85+
$index = $container->getParameterBag()->resolveValue($index) ?: null;
86+
}
87+
if (null === $index && null === $defaultIndex && $defaultPriorityMethod && $class) {
8788
$defaultIndex = PriorityTaggedServiceUtil::getDefault($container, $serviceId, $class, $defaultIndexMethod ?? 'getDefaultName', $tagName, $indexAttribute, $checkTaggedItem);
8889
}
8990
$index ??= $defaultIndex ??= $serviceId;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,20 @@ public function testResolveIndexedTags()
232232
$container = new ContainerBuilder();
233233
$container->setParameter('custom_param_service1', 'bar');
234234
$container->setParameter('custom_param_service2', 'baz');
235+
$container->setParameter('custom_param_service2_empty', '');
235236
$container->register('service1')->addTag('my_custom_tag', ['foo' => '%custom_param_service1%']);
236237

237238
$definition = $container->register('service2', BarTagClass::class);
238239
$definition->addTag('my_custom_tag', ['foo' => '%custom_param_service2%', 'priority' => 100]);
240+
$definition->addTag('my_custom_tag', ['foo' => '%custom_param_service2_empty%']);
239241

240242
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
241243

242-
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo');
244+
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
243245
$expected = [
244246
'baz' => new TypedReference('service2', BarTagClass::class),
245247
'bar' => new Reference('service1'),
248+
'bar_tab_class_with_defaultmethod' => new TypedReference('service2', BarTagClass::class),
246249
];
247250
$services = $priorityTaggedServiceTraitImplementation->test($tag, $container);
248251
$this->assertSame(array_keys($expected), array_keys($services));

0 commit comments

Comments
 (0)
0