Skip to content

Commit 608e126

Browse files
Merge branch '6.4' into 7.3
* 6.4: [Cache] Fix internal representation of non-static values [Cache] Make `TagAwareAdapter` registrable as a service refactor: Unify & more humane translation message fix Resources translations validators.pt.xlf [Security] Pass attributes to nested `ChainUserProviders` [Validator] Update translation for the Video constraint [Messenger] Firebird Database - incompatibility with expected lowercase columns SQLSRV: Change column type from TEXT to STRING Fix exception catch when deleting temporary table in the sameDatabaseChecker [Serializer] Fix serializer crash due to asymmetric visibility on `protected(set)` properties
2 parents 87ba5d8 + e3b664d commit 608e126

File tree

71 files changed

+4958
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4958
-111
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\SchemaListener;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
1516
use Doctrine\DBAL\Exception\TableNotFoundException;
1617
use Doctrine\DBAL\Schema\Name\Identifier;
1718
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
@@ -52,7 +53,7 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
5253
$schemaManager->dropTable($checkTable);
5354

5455
return false;
55-
} catch (TableNotFoundException) {
56+
} catch (DatabaseObjectNotFoundException) {
5657
return true;
5758
}
5859
};

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1818
use Symfony\Component\Cache\PruneableInterface;
1919
use Symfony\Component\Cache\ResettableInterface;
20+
use Symfony\Component\Cache\Traits\CachedValueInterface;
2021
use Symfony\Component\Cache\Traits\ContractsTrait;
2122
use Symfony\Component\Cache\Traits\ProxyTrait;
2223
use Symfony\Component\VarExporter\VarExporter;
@@ -96,16 +97,15 @@ public function get(string $key, callable $callback, ?float $beta = null, ?array
9697
if ('N;' === $value) {
9798
return null;
9899
}
100+
if (!$value instanceof CachedValueInterface) {
101+
return $value;
102+
}
99103
try {
100-
if ($value instanceof \Closure) {
101-
return $value();
102-
}
104+
return $value->getValue();
103105
} catch (\Throwable) {
104106
unset($this->keys[$key]);
105107
goto get_from_pool;
106108
}
107-
108-
return $value;
109109
}
110110

111111
public function getItem(mixed $key): CacheItem
@@ -125,9 +125,9 @@ public function getItem(mixed $key): CacheItem
125125

126126
if ('N;' === $value) {
127127
$value = null;
128-
} elseif ($value instanceof \Closure) {
128+
} elseif ($value instanceof CachedValueInterface) {
129129
try {
130-
$value = $value();
130+
$value = $value->getValue();
131131
} catch (\Throwable) {
132132
$value = null;
133133
$isHit = false;
@@ -306,8 +306,7 @@ public function warmUp(array $values): array
306306
}
307307

308308
if (!$isStaticValue) {
309-
$value = str_replace("\n", "\n ", $value);
310-
$value = "static function () {\n return {$value};\n}";
309+
$value = 'new class() implements \\'.CachedValueInterface::class." { public function getValue(): mixed { return {$value}; } }";
311310
}
312311
$hash = hash('xxh128', $value);
313312

@@ -368,9 +367,9 @@ private function generateItems(array $keys): \Generator
368367

369368
if ('N;' === $value) {
370369
yield $key => $f($key, null, true);
371-
} elseif ($value instanceof \Closure) {
370+
} elseif ($value instanceof CachedValueInterface) {
372371
try {
373-
yield $key => $f($key, $value(), true);
372+
yield $key => $f($key, $value->getValue(), true);
374373
} catch (\Throwable) {
375374
yield $key => $f($key, null, false);
376375
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Cache\Exception\CacheException;
1515
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1616
use Symfony\Component\Cache\PruneableInterface;
17+
use Symfony\Component\Cache\Traits\CachedValueInterface;
1718
use Symfony\Component\Cache\Traits\FilesystemCommonTrait;
1819
use Symfony\Component\VarExporter\VarExporter;
1920

@@ -113,8 +114,10 @@ protected function doFetch(array $ids): iterable
113114
$values[$id] = null;
114115
} elseif (!\is_object($value)) {
115116
$values[$id] = $value;
117+
} elseif ($value instanceof CachedValueInterface) {
118+
$values[$id] = $value->getValue();
116119
} elseif (!$value instanceof LazyValue) {
117-
$values[$id] = $value();
120+
$values[$id] = $value;
118121
} elseif (false === $values[$id] = include $value->file) {
119122
unset($values[$id], $this->values[$id]);
120123
$missingIds[] = $id;
@@ -235,7 +238,7 @@ protected function doSave(array $values, int $lifetime): array|bool
235238
if ($isStaticValue) {
236239
$value = "return [{$expiry}, {$value}];";
237240
} elseif ($this->appendOnly) {
238-
$value = "return [{$expiry}, static fn () => {$value}];";
241+
$value = "return [{$expiry}, new class() implements \\".CachedValueInterface::class." { public function getValue(): mixed { return {$value}; } }];";
239242
} else {
240243
// We cannot use a closure here because of https://bugs.php.net/76982
241244
$value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value);

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Cache\Adapter\ChainAdapter;
1717
use Symfony\Component\Cache\Adapter\NullAdapter;
1818
use Symfony\Component\Cache\Adapter\ParameterNormalizer;
19+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1920
use Symfony\Component\Cache\Messenger\EarlyExpirationDispatcher;
2021
use Symfony\Component\DependencyInjection\ChildDefinition;
2122
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -153,7 +154,7 @@ public function process(ContainerBuilder $container): void
153154
),
154155
]);
155156
$pool->addTag('container.reversible');
156-
} elseif ('namespace' !== $attr || !\in_array($class, [ArrayAdapter::class, NullAdapter::class], true)) {
157+
} elseif ('namespace' !== $attr || !\in_array($class, [ArrayAdapter::class, NullAdapter::class, TagAwareAdapter::class], true)) {
157158
$argument = $tags[0][$attr];
158159

159160
if ('default_lifetime' === $attr && !is_numeric($argument)) {

src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Cache\Adapter\ChainAdapter;
1818
use Symfony\Component\Cache\Adapter\NullAdapter;
1919
use Symfony\Component\Cache\Adapter\RedisAdapter;
20+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
2021
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
2122
use Symfony\Component\DependencyInjection\ChildDefinition;
2223
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -102,15 +103,18 @@ public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectin
102103
$this->assertSame('mVXLns1cYU', $cachePool->getArgument(0));
103104
}
104105

105-
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
106+
/**
107+
* @dataProvider providerAdaptersNotNamespace
108+
*/
109+
public function testNamespaceArgumentIsNotReplacedIfAdapterWithoutNamespace(string $adapterClass)
106110
{
107111
$container = new ContainerBuilder();
108112
$container->setParameter('kernel.container_class', 'app');
109113
$container->setParameter('kernel.project_dir', 'foo');
110114

111-
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
115+
$container->register('cache.adapter', $adapterClass)->addArgument(0);
112116

113-
$cachePool = new ChildDefinition('cache.adapter.array');
117+
$cachePool = new ChildDefinition('cache.adapter');
114118
$cachePool->addTag('cache.pool');
115119
$container->setDefinition('app.cache_pool', $cachePool);
116120

@@ -119,21 +123,11 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
119123
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
120124
}
121125

122-
public function testNamespaceArgumentIsNotReplacedIfNullAdapterIsUsed()
126+
public static function providerAdaptersNotNamespace(): iterable
123127
{
124-
$container = new ContainerBuilder();
125-
$container->setParameter('kernel.container_class', 'app');
126-
$container->setParameter('kernel.project_dir', 'foo');
127-
128-
$container->register('cache.adapter.null', NullAdapter::class);
129-
130-
$cachePool = new ChildDefinition('cache.adapter.null');
131-
$cachePool->addTag('cache.pool');
132-
$container->setDefinition('app.cache_pool', $cachePool);
133-
134-
$this->cachePoolPass->process($container);
135-
136-
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
128+
yield [ArrayAdapter::class];
129+
yield [NullAdapter::class];
130+
yield [TagAwareAdapter::class];
137131
}
138132

139133
public function testArgsAreReplaced()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
/**
15+
* @internal
16+
*/
17+
interface CachedValueInterface
18+
{
19+
public function getValue(): mixed;
20+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null
219219
$table->addColumn($this->timeCol, Types::INTEGER)->setNotnull(true);
220220
break;
221221
case 'sqlsrv':
222-
$table->addColumn($this->idCol, Types::TEXT)->setLength(128)->setNotnull(true);
222+
$table->addColumn($this->idCol, Types::STRING)->setLength(128)->setNotnull(true);
223223
$table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
224224
$table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
225225
$table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Doctrine\DBAL\Schema\Schema;
3434
use Doctrine\DBAL\Schema\Table;
3535
use Doctrine\DBAL\Types\Types;
36+
use Satag\DoctrineFirebirdDriver\Platforms\FirebirdPlatform;
3637
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
3738
use Symfony\Component\Messenger\Exception\TransportException;
3839
use Symfony\Contracts\Service\ResetInterface;
@@ -431,7 +432,9 @@ private function createQueryBuilder(string $alias = 'm'): QueryBuilder
431432

432433
$alias .= '.';
433434

434-
if (!$this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
435+
if (!$this->driverConnection->getDatabasePlatform() instanceof FirebirdPlatform
436+
&& !$this->driverConnection->getDatabasePlatform() instanceof OraclePlatform
437+
) {
435438
return $queryBuilder->select($alias.'*');
436439
}
437440

src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public function testLoadUserByIdentifier()
4949

5050
public function testLoadUserByIdentifierWithAttributes()
5151
{
52+
$provider0 = $this->createMock(ChainUserProvider::class);
53+
$provider0
54+
->expects($this->once())
55+
->method('loadUserByIdentifier')
56+
->with($this->equalTo('foo'), $this->equalTo(['attr' => 5]))
57+
->willThrowException(new UserNotFoundException('not found'))
58+
;
59+
5260
$provider1 = $this->createMock(UserProviderInterface::class);
5361
$provider1
5462
->expects($this->once())
@@ -65,7 +73,7 @@ public function testLoadUserByIdentifierWithAttributes()
6573
->willReturn($account = $this->createMock(UserInterface::class))
6674
;
6775

68-
$provider = new ChainUserProvider([$provider1, $provider2]);
76+
$provider = new ChainUserProvider([$provider0, $provider1, $provider2]);
6977
$this->assertSame($account, $provider->loadUserByIdentifier('foo', ['attr' => 5]));
7078
}
7179

src/Symfony/Component/Security/Core/User/ChainUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function loadUserByIdentifier(string $identifier/* , array $attributes =
5454
$attributes = \func_num_args() > 1 ? func_get_arg(1) : [];
5555
foreach ($this->providers as $provider) {
5656
try {
57-
if ($provider instanceof AttributesBasedUserProviderInterface) {
57+
if ($provider instanceof AttributesBasedUserProviderInterface || $provider instanceof self) {
5858
return $provider->loadUserByIdentifier($identifier, $attributes);
5959
}
6060

0 commit comments

Comments
 (0)