Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"symfony/console": "^5.4 || ^6.4 || ^7.0 || ^8.0",
"symfony/deprecation-contracts": "^2.2 || ^3.0",
"symfony/var-dumper": "^5.4 || ^6.4 || ^7.0 || ^8.0",
"symfony/var-exporter": "^6.4 || ^7.0"
"symfony/var-exporter": "^6.4 || ^7.0 || ^8.0"
},
"require-dev": {
"ext-bcmath": "*",
Expand Down
12 changes: 10 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Psr\Cache\CacheItemPoolInterface;
use ReflectionClass;
use stdClass;
use Symfony\Component\VarExporter\LazyGhostTrait;
use Throwable;

use function array_diff_key;
Expand All @@ -44,6 +45,7 @@
use function class_exists;
use function interface_exists;
use function is_string;
use function trait_exists;
use function trigger_deprecation;
use function trim;

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

if ($flag === false) {
if ($flag && ! trait_exists(LazyGhostTrait::class)) {
throw new LogicException('Package "symfony/var-exporter" >= 8.0 does not provide lazy ghost objects, use native lazy objects instead.');
}

if (! $flag) {
if (! class_exists(ProxyManagerConfiguration::class)) {
throw new LogicException('Package "friendsofphp/proxy-manager-lts" is required to disable LazyGhostObject.');
}

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

$this->lazyGhostObject = $flag;
Expand Down
21 changes: 21 additions & 0 deletions tests/Tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ODM\MongoDB\Tests;

use Composer\InstalledVersions;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\ConfigurationException;
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionFactory;
Expand All @@ -17,6 +18,7 @@

use function base64_encode;
use function str_repeat;
use function version_compare;

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

public function testUseLazyGhostObject(): void
{
if (! version_compare(InstalledVersions::getVersion('symfony/var-exporter'), '8', '<')) {
$this->markTestSkipped('Symfony VarExporter 8 or higher is not installed.');
}

$c = new Configuration();

self::assertFalse($c->isLazyGhostObjectEnabled());
Expand All @@ -42,6 +48,21 @@ public function testUseLazyGhostObject(): void
self::assertFalse($c->isLazyGhostObjectEnabled());
}

#[RequiresPhp('>= 8.4')]
public function testUseLazyGhostObjectWithSymfony8(): void
{
if (version_compare(InstalledVersions::getVersion('symfony/var-exporter'), '8', '<')) {
$this->markTestSkipped('Symfony VarExporter 8 or higher is not installed.');
}

$c = new Configuration();

self::expectException(LogicException::class);
self::expectExceptionMessage('Package "symfony/var-exporter" >= 8.0 does not provide lazy ghost objects, use native lazy objects instead.');

$c->setUseLazyGhostObject(true);
}

public function testNativeLazyObjectDeprecatedByDefault(): void
{
$c = new Configuration();
Expand Down