Skip to content

Commit 690ab9a

Browse files
Merge branch '7.3' into 7.4
* 7.3: [Config] Fix `ReflectionClassResource` hash validation [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 [JsonStreamer] Fix encoding iterable lists [Serializer] Fix serializer crash due to asymmetric visibility on `protected(set)` properties [DependencyInjection] Respect original service class when a proxy is defined
2 parents 4919062 + 608e126 commit 690ab9a

File tree

81 files changed

+5109
-121
lines changed

Some content is hidden

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

81 files changed

+5109
-121
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: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Component\Cache\Tests\DependencyInjection;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1617
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1718
use Symfony\Component\Cache\Adapter\ChainAdapter;
1819
use Symfony\Component\Cache\Adapter\NullAdapter;
1920
use Symfony\Component\Cache\Adapter\RedisAdapter;
21+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
2022
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
2123
use Symfony\Component\DependencyInjection\ChildDefinition;
2224
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -102,15 +104,16 @@ public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectin
102104
$this->assertSame('mVXLns1cYU', $cachePool->getArgument(0));
103105
}
104106

105-
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
107+
#[DataProvider('providerAdaptersNotNamespace')]
108+
public function testNamespaceArgumentIsNotReplacedIfAdapterWithoutNamespace(string $adapterClass)
106109
{
107110
$container = new ContainerBuilder();
108111
$container->setParameter('kernel.container_class', 'app');
109112
$container->setParameter('kernel.project_dir', 'foo');
110113

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

113-
$cachePool = new ChildDefinition('cache.adapter.array');
116+
$cachePool = new ChildDefinition('cache.adapter');
114117
$cachePool->addTag('cache.pool');
115118
$container->setDefinition('app.cache_pool', $cachePool);
116119

@@ -119,21 +122,11 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
119122
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
120123
}
121124

122-
public function testNamespaceArgumentIsNotReplacedIfNullAdapterIsUsed()
125+
public static function providerAdaptersNotNamespace(): iterable
123126
{
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());
127+
yield [ArrayAdapter::class];
128+
yield [NullAdapter::class];
129+
yield [TagAwareAdapter::class];
137130
}
138131

139132
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/Config/Resource/ReflectionClassResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function __serialize(): array
6969
return [
7070
'files' => $this->files,
7171
'className' => $this->className,
72+
'excludedVendors' => $this->excludedVendors,
7273
'hash' => $this->hash,
7374
];
7475
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Config\Tests\Fixtures\FakeVendor;
13+
14+
abstract class Base
15+
{
16+
public $baseFoo;
17+
18+
protected $baseBar;
19+
20+
public function baseBaz()
21+
{
22+
}
23+
24+
public function baseQux()
25+
{
26+
}
27+
}

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Attributes\DataProvider;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Config\Resource\ReflectionClassResource;
17+
use Symfony\Component\Config\Tests\Fixtures\FakeVendor\Base;
1718
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1819
use Symfony\Contracts\Service\ServiceSubscriberInterface;
1920

@@ -70,7 +71,7 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
7071

7172
$code = <<<'EOPHP'
7273
/* 0*/
73-
/* 1*/ class %s extends ErrorException
74+
/* 1*/ class %s extends %s
7475
/* 2*/ {
7576
/* 3*/ const FOO = 123;
7677
/* 4*/
@@ -90,22 +91,27 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
9091
/*18*/ }
9192
EOPHP;
9293

93-
static $expectedSignature, $generateSignature;
94+
static $expectedSignature, $signatureGenerator;
9495

9596
if (null === $expectedSignature) {
96-
eval(\sprintf($code, $class = 'Foo'.(string) $resourceClassNameSuffix));
97+
eval(\sprintf($code, $class = 'Foo'.(string) $resourceClassNameSuffix, Base::class));
98+
9799
$r = new \ReflectionClass(ReflectionClassResource::class);
98100
$generateSignature = $r->getMethod('generateSignature');
99-
$generateSignature = $generateSignature->getClosure($r->newInstanceWithoutConstructor());
100-
$expectedSignature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
101+
102+
$res = new ReflectionClassResource(new \ReflectionClass($class), [\dirname(__DIR__).'/Fixtures/FakeVendor']);
103+
$signatureGenerator = $generateSignature->getClosure($res);
104+
$expectedSignature = implode("\n", iterator_to_array($signatureGenerator(new \ReflectionClass($class))));
105+
106+
$signatureGenerator = $generateSignature->getClosure(unserialize(serialize($res)));
101107
}
102108

103109
$code = explode("\n", $code);
104110
if (null !== $changedCode) {
105111
$code[$changedLine] = $changedCode;
106112
}
107-
eval(\sprintf(implode("\n", $code), $class = 'Bar'.(string) $resourceClassNameSuffix));
108-
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
113+
eval(\sprintf(implode("\n", $code), $class = 'Bar'.(string) $resourceClassNameSuffix, Base::class));
114+
$signature = implode("\n", iterator_to_array($signatureGenerator(new \ReflectionClass($class))));
109115

110116
if ($changeExpected) {
111117
$this->assertNotSame($expectedSignature, $signature);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,13 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
334334
$value = $attribute->buildDefinition($value, $type, $parameter);
335335
$value = $this->doProcessValue($value);
336336
} elseif ($lazy = $attribute->lazy) {
337+
$value ??= $getValue();
338+
if ($this->container->has($value->getType())) {
339+
$type = $this->container->findDefinition($value->getType())->getClass();
340+
}
337341
$definition = (new Definition($type))
338342
->setFactory('current')
339-
->setArguments([[$value ??= $getValue()]])
343+
->setArguments([[$value]])
340344
->setLazy(true);
341345

342346
if (!\is_array($lazy)) {

0 commit comments

Comments
 (0)