Skip to content

Commit 5b287ff

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Security][TwigBridge] Add access_decision() and access_decision_for_user() [DependencyInjection] Optimize `AutowireRequiredMethodsPass` [Config] Fix `ReflectionClassResource` hash validation [Cache] Fix internal representation of non-static values [Cache] Make `TagAwareAdapter` registrable as a service [Validator] Add the Video constraint for validating video files refactor: Unify & more humane translation message [DependencyInjection] Allow multiple `#[AsDecorator]` attributes fix Resources translations validators.pt.xlf [Security] Pass attributes to nested `ChainUserProviders` [Runtime] Expose the runtime class in `$_SERVER['APP_RUNTIME']` [Validator] Update translation for the Video constraint [Messenger] Firebird Database - incompatibility with expected lowercase columns SQLSRV: Change column type from TEXT to STRING [DependencyInjection] Parse attributes found on abstract classes for resource definitions Fix exception catch when deleting temporary table in the sameDatabaseChecker [JsonStreamer] Fix encoding iterable lists [Console] Harden array type for test-related user inputs [Serializer] Fix serializer crash due to asymmetric visibility on `protected(set)` properties [DependencyInjection] Respect original service class when a proxy is defined
2 parents 75fa734 + 4cb36ef commit 5b287ff

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

DependencyInjection/StreamablePass.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1617

1718
/**
1819
* Sets the streamable metadata to the services that need them.
@@ -31,16 +32,20 @@ public function process(ContainerBuilder $container): void
3132

3233
// retrieve concrete services tagged with "json_streamer.streamable" tag
3334
foreach ($container->getDefinitions() as $id => $definition) {
34-
if (!$tag = ($definition->getTag('json_streamer.streamable')[0] ?? null)) {
35+
if (!$tag = $definition->getTag('json_streamer.streamable')[0] ?? null) {
3536
continue;
3637
}
37-
38-
if (($className = $container->getDefinition($id)->getClass()) && !$container->getDefinition($id)->isAbstract()) {
39-
$streamable[$className] = [
40-
'object' => $tag['object'],
41-
'list' => $tag['list'],
42-
];
38+
if (!$definition->hasTag('container.excluded')) {
39+
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "json_streamer.streamable" is missing the "container.excluded" tag.', $id));
40+
}
41+
$class = $container->getParameterBag()->resolveValue($definition->getClass());
42+
if (!$class || $definition->isAbstract()) {
43+
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "json_streamer.streamable" must have a class and not be abstract.', $id));
4344
}
45+
$streamable[$class] = [
46+
'object' => $tag['object'],
47+
'list' => $tag['list'],
48+
];
4449

4550
$container->removeDefinition($id);
4651
}

Tests/DependencyInjection/StreamablePassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1617
use Symfony\Component\JsonStreamer\DependencyInjection\StreamablePass;
1718

1819
class StreamablePassTest extends TestCase
@@ -24,8 +25,7 @@ public function testSetStreamable()
2425
$container->register('json_streamer.stream_writer');
2526
$container->register('.json_streamer.cache_warmer.streamer')->setArguments([null]);
2627

27-
$container->register('streamable')->setClass('Foo')->addTag('json_streamer.streamable', ['object' => true, 'list' => true]);
28-
$container->register('abstractStreamable')->setClass('Bar')->addTag('json_streamer.streamable', ['object' => true, 'list' => true])->setAbstract(true);
28+
$container->register('streamable')->setClass('Foo')->addTag('json_streamer.streamable', ['object' => true, 'list' => true])->addTag('container.excluded');
2929
$container->register('notStreamable')->setClass('Baz');
3030

3131
$pass = new StreamablePass();
@@ -34,5 +34,9 @@ public function testSetStreamable()
3434
$streamerCacheWarmer = $container->getDefinition('.json_streamer.cache_warmer.streamer');
3535

3636
$this->assertSame(['Foo' => ['object' => true, 'list' => true]], $streamerCacheWarmer->getArgument(0));
37+
38+
$container->register('abstractStreamable')->setClass('Bar')->addTag('json_streamer.streamable', ['object' => true, 'list' => true])->addTag('container.excluded')->setAbstract(true);
39+
$this->expectException(InvalidArgumentException::class);
40+
$pass->process($container);
3741
}
3842
}

Tests/JsonStreamWriterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testWriteCollection()
107107
);
108108

109109
$this->assertWritten(
110-
'{"0":{"id":1,"name":"dummy"},"1":{"id":1,"name":"dummy"}}',
110+
'[{"id":1,"name":"dummy"},{"id":1,"name":"dummy"}]',
111111
new \ArrayObject([new ClassicDummy(), new ClassicDummy()]),
112112
Type::iterable(Type::object(ClassicDummy::class), Type::int()),
113113
);

Write/PhpGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ private function generateYields(DataModelNodeInterface $dataModelNode, array $op
191191
if ($dataModelNode instanceof CollectionNode) {
192192
++$context['depth'];
193193

194-
if ($dataModelNode->getType()->isList()) {
194+
$collectionKeyType = $dataModelNode->getType()->getCollectionKeyType();
195+
196+
if ($collectionKeyType instanceof BuiltinType && TypeIdentifier::INT === $collectionKeyType->getTypeIdentifier()) {
195197
$php = $this->yieldInterpolatedString('[', $context)
196198
.$this->flushYieldBuffer($context)
197199
.$this->line('$prefix'.$context['depth'].' = \'\';', $context)

0 commit comments

Comments
 (0)