Skip to content

Commit 2287b06

Browse files
authored
Enable symfony/var-exporter 8.0, without lazy ghost object support (#2882)
1 parent c11783a commit 2287b06

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"symfony/console": "^5.4 || ^6.4 || ^7.0 || ^8.0",
4141
"symfony/deprecation-contracts": "^2.2 || ^3.0",
4242
"symfony/var-dumper": "^5.4 || ^6.4 || ^7.0 || ^8.0",
43-
"symfony/var-exporter": "^6.4 || ^7.0"
43+
"symfony/var-exporter": "^6.4 || ^7.0 || ^8.0"
4444
},
4545
"require-dev": {
4646
"ext-bcmath": "*",

src/Configuration.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Psr\Cache\CacheItemPoolInterface;
3737
use ReflectionClass;
3838
use stdClass;
39+
use Symfony\Component\VarExporter\LazyGhostTrait;
3940
use Throwable;
4041

4142
use function array_diff_key;
@@ -44,6 +45,7 @@
4445
use function class_exists;
4546
use function interface_exists;
4647
use function is_string;
48+
use function trait_exists;
4749
use function trigger_deprecation;
4850
use function trim;
4951

@@ -695,12 +697,18 @@ public function setUseLazyGhostObject(bool $flag): void
695697
throw new LogicException('Cannot enable or disable LazyGhostObject when native lazy objects are enabled.');
696698
}
697699

698-
if ($flag === false) {
700+
if ($flag && ! trait_exists(LazyGhostTrait::class)) {
701+
throw new LogicException('Package "symfony/var-exporter" >= 8.0 does not provide lazy ghost objects, use native lazy objects instead.');
702+
}
703+
704+
if (! $flag) {
699705
if (! class_exists(ProxyManagerConfiguration::class)) {
700706
throw new LogicException('Package "friendsofphp/proxy-manager-lts" is required to disable LazyGhostObject.');
701707
}
702708

703-
trigger_deprecation('doctrine/mongodb-odm', '2.10', 'Using "friendsofphp/proxy-manager-lts" is deprecated. Use "symfony/var-exporter" LazyGhostObjects instead.');
709+
if (PHP_VERSION_ID < 80400) {
710+
trigger_deprecation('doctrine/mongodb-odm', '2.10', 'Using "friendsofphp/proxy-manager-lts" is deprecated. Use "symfony/var-exporter" LazyGhostObjects instead.');
711+
}
704712
}
705713

706714
$this->lazyGhostObject = $flag;

tests/Tests/ConfigurationTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ODM\MongoDB\Tests;
66

7+
use Composer\InstalledVersions;
78
use Doctrine\ODM\MongoDB\Configuration;
89
use Doctrine\ODM\MongoDB\ConfigurationException;
910
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionFactory;
@@ -17,6 +18,7 @@
1718

1819
use function base64_encode;
1920
use function str_repeat;
21+
use function version_compare;
2022

2123
class ConfigurationTest extends TestCase
2224
{
@@ -33,6 +35,10 @@ public function testUseNativeLazyObjectBeforePHP84(): void
3335

3436
public function testUseLazyGhostObject(): void
3537
{
38+
if (! version_compare(InstalledVersions::getVersion('symfony/var-exporter'), '8', '<')) {
39+
$this->markTestSkipped('Symfony VarExporter 8 or higher is not installed.');
40+
}
41+
3642
$c = new Configuration();
3743

3844
self::assertFalse($c->isLazyGhostObjectEnabled());
@@ -42,6 +48,21 @@ public function testUseLazyGhostObject(): void
4248
self::assertFalse($c->isLazyGhostObjectEnabled());
4349
}
4450

51+
#[RequiresPhp('>= 8.4')]
52+
public function testUseLazyGhostObjectWithSymfony8(): void
53+
{
54+
if (version_compare(InstalledVersions::getVersion('symfony/var-exporter'), '8', '<')) {
55+
$this->markTestSkipped('Symfony VarExporter 8 or higher is not installed.');
56+
}
57+
58+
$c = new Configuration();
59+
60+
self::expectException(LogicException::class);
61+
self::expectExceptionMessage('Package "symfony/var-exporter" >= 8.0 does not provide lazy ghost objects, use native lazy objects instead.');
62+
63+
$c->setUseLazyGhostObject(true);
64+
}
65+
4566
public function testNativeLazyObjectDeprecatedByDefault(): void
4667
{
4768
$c = new Configuration();

0 commit comments

Comments
 (0)