Skip to content

Commit f67a1ce

Browse files
Merge branch '7.2' into 7.3
* 7.2: use Table::addPrimaryKeyConstraint() with Doctrine DBAL 4.3+ [Serializer] Fix ObjectNormalizer default context with named serializers [Serializer] Fix code skipped by premature return [TypeInfo] Fix `isSatisfiedBy` not traversing type tree Update JsDelivrEsmResolver::IMPORT_REGEX to support dynamic imports
2 parents 12c73a1 + 2276608 commit f67a1ce

File tree

16 files changed

+198
-45
lines changed

16 files changed

+198
-45
lines changed

src/Symfony/Bridge/Doctrine/SchemaListener/AbstractSchemaListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\Exception\TableNotFoundException;
16+
use Doctrine\DBAL\Schema\Name\Identifier;
17+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
18+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
1619
use Doctrine\DBAL\Schema\Table;
1720
use Doctrine\DBAL\Types\Types;
1821
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
@@ -30,7 +33,12 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
3033
$table->addColumn('id', Types::INTEGER)
3134
->setAutoincrement(true)
3235
->setNotnull(true);
33-
$table->setPrimaryKey(['id']);
36+
37+
if (class_exists(PrimaryKeyConstraint::class)) {
38+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted('id'))], true));
39+
} else {
40+
$table->setPrimaryKey(['id']);
41+
}
3442

3543
$schemaManager->createTable($table);
3644

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\ParameterType;
16+
use Doctrine\DBAL\Schema\Name\Identifier;
17+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
18+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
1619
use Doctrine\DBAL\Schema\Schema;
1720
use Doctrine\DBAL\Types\Types;
1821
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
@@ -194,6 +197,11 @@ private function addTableToSchema(Schema $schema): void
194197
$table->addColumn('lastUsed', Types::DATETIME_IMMUTABLE);
195198
$table->addColumn('class', Types::STRING, ['length' => 100]);
196199
$table->addColumn('username', Types::STRING, ['length' => 200]);
197-
$table->setPrimaryKey(['series']);
200+
201+
if (class_exists(PrimaryKeyConstraint::class)) {
202+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted('series'))], true));
203+
} else {
204+
$table->setPrimaryKey(['series']);
205+
}
198206
}
199207
}

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,24 +2066,14 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
20662066
$container->setParameter('serializer.default_context', $defaultContext);
20672067
}
20682068

2069-
if (!$container->hasDefinition('serializer.normalizer.object')) {
2070-
return;
2071-
}
2072-
2073-
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
2074-
$context = $arguments[6] ?? $defaultContext;
2075-
2076-
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
2077-
$context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
2078-
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
2069+
if ($config['circular_reference_handler'] ?? false) {
2070+
$container->setParameter('.serializer.circular_reference_handler', $config['circular_reference_handler']);
20792071
}
20802072

20812073
if ($config['max_depth_handler'] ?? false) {
2082-
$context += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
2074+
$container->setParameter('.serializer.max_depth_handler', $config['max_depth_handler']);
20832075
}
20842076

2085-
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
2086-
20872077
$container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext);
20882078

20892079
$container->setParameter('.serializer.named_serializers', $config['named_serializers'] ?? []);

src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
service('property_info')->ignoreOnInvalid(),
131131
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
132132
null,
133-
null,
133+
abstract_arg('default context, set in the SerializerPass'),
134134
service('property_info')->ignoreOnInvalid(),
135135
])
136136
->tag('serializer.normalizer', ['built_in' => true, 'priority' => -1000])

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
3434
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
3535
use Symfony\Component\DependencyInjection\ChildDefinition;
36+
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
3637
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
3738
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
3839
use Symfony\Component\DependencyInjection\Compiler\ResolveTaggedIteratorArgumentPass;
@@ -68,6 +69,7 @@
6869
use Symfony\Component\Notifier\TexterInterface;
6970
use Symfony\Component\PropertyAccess\PropertyAccessor;
7071
use Symfony\Component\Security\Core\AuthenticationEvents;
72+
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
7173
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
7274
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
7375
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
@@ -1525,9 +1527,6 @@ public function testSerializerEnabled()
15251527
$this->assertEquals(AttributeLoader::class, $argument[0]->getClass());
15261528
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.name_converter.metadata_aware')->getArgument(1));
15271529
$this->assertEquals(new Reference('property_info', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), $container->getDefinition('serializer.normalizer.object')->getArgument(3));
1528-
$this->assertArrayHasKey('circular_reference_handler', $container->getDefinition('serializer.normalizer.object')->getArgument(6));
1529-
$this->assertArrayHasKey('max_depth_handler', $container->getDefinition('serializer.normalizer.object')->getArgument(6));
1530-
$this->assertEquals($container->getDefinition('serializer.normalizer.object')->getArgument(6)['max_depth_handler'], new Reference('my.max.depth.handler'));
15311530
}
15321531

15331532
public function testSerializerWithoutTranslator()
@@ -1625,13 +1624,22 @@ public function testJsonSerializableNormalizerRegistered()
16251624

16261625
public function testObjectNormalizerRegistered()
16271626
{
1628-
$container = $this->createContainerFromFile('full');
1627+
$container = $this->createContainerFromFile('full', compile: false);
1628+
$container->addCompilerPass(new SerializerPass());
1629+
$container->addCompilerPass(new ResolveBindingsPass());
1630+
$container->compile();
16291631

16301632
$definition = $container->getDefinition('serializer.normalizer.object');
16311633
$tag = $definition->getTag('serializer.normalizer');
16321634

16331635
$this->assertEquals(ObjectNormalizer::class, $definition->getClass());
16341636
$this->assertEquals(-1000, $tag[0]['priority']);
1637+
1638+
$this->assertEquals([
1639+
'enable_max_depth' => true,
1640+
'circular_reference_handler' => new Reference('my.circular.reference.handler'),
1641+
'max_depth_handler' => new Reference('my.max.depth.handler'),
1642+
], $definition->getArgument(6));
16351643
}
16361644

16371645
public function testConstraintViolationListNormalizerRegistered()

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"symfony/scheduler": "^6.4.4|^7.0.4",
6161
"symfony/security-bundle": "^6.4|^7.0",
6262
"symfony/semaphore": "^6.4|^7.0",
63-
"symfony/serializer": "^7.1",
63+
"symfony/serializer": "^7.2.5",
6464
"symfony/stopwatch": "^6.4|^7.0",
6565
"symfony/string": "^6.4|^7.0",
6666
"symfony/translation": "^7.3",
@@ -100,7 +100,7 @@
100100
"symfony/scheduler": "<6.4.4|>=7.0.0,<7.0.4",
101101
"symfony/security-csrf": "<7.2",
102102
"symfony/security-core": "<6.4",
103-
"symfony/serializer": "<7.1",
103+
"symfony/serializer": "<7.2.5",
104104
"symfony/stopwatch": "<6.4",
105105
"symfony/translation": "<7.3",
106106
"symfony/twig-bridge": "<6.4",

src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2828
public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm';
2929
public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints';
3030

31-
public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#';
31+
public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*|await\simport\()("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")(?:\)*)#';
3232

3333
private const ES_MODULE_SHIMS = 'es-module-shims';
3434

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@ public static function provideImportRegex(): iterable
693693
['jquery', '3.7.0'],
694694
],
695695
];
696+
697+
yield 'dynamic import with path' => [
698+
'return(await import("/npm/@datadog/[email protected]/esm/boot/startRecording.js/+esm")).startRecording',
699+
[
700+
['@datadog/browser-rum/esm/boot/startRecording.js', '6.3.0'],
701+
],
702+
];
696703
}
697704

698705
private static function createRemoteEntry(string $importName, string $version, ImportMapType $type = ImportMapType::JS, ?string $packageSpecifier = null): ImportMapEntry

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Doctrine\DBAL\Exception\TableNotFoundException;
2020
use Doctrine\DBAL\ParameterType;
2121
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
22+
use Doctrine\DBAL\Schema\Name\Identifier;
23+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
24+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
2225
use Doctrine\DBAL\Schema\Schema;
2326
use Doctrine\DBAL\Tools\DsnParser;
2427
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@@ -378,6 +381,11 @@ private function addTableToSchema(Schema $schema): void
378381
$table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
379382
$table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
380383
$table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
381-
$table->setPrimaryKey([$this->idCol]);
384+
385+
if (class_exists(PrimaryKeyConstraint::class)) {
386+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
387+
} else {
388+
$table->setPrimaryKey([$this->idCol]);
389+
}
382390
}
383391
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

14+
use Doctrine\DBAL\Schema\Name\Identifier;
15+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
16+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
1417
use Doctrine\DBAL\Schema\Schema;
1518
use Doctrine\DBAL\Types\Types;
1619

@@ -224,7 +227,13 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null
224227
default:
225228
throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
226229
}
227-
$table->setPrimaryKey([$this->idCol]);
230+
231+
if (class_exists(PrimaryKeyConstraint::class)) {
232+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
233+
} else {
234+
$table->setPrimaryKey([$this->idCol]);
235+
}
236+
228237
$table->addIndex([$this->lifetimeCol], $this->lifetimeCol.'_idx');
229238
}
230239

0 commit comments

Comments
 (0)