Skip to content

Commit 9685d02

Browse files
Only enable native lazy objects in PHP 8.4+
1 parent 743a4a0 commit 9685d02

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

webapp/config/packages/doctrine.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ doctrine:
3131
controller_resolver:
3232
auto_mapping: false
3333
enable_lazy_ghost_objects: true
34-
enable_native_lazy_objects: true
3534
mappings:
3635
App:
3736
type: attribute
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class DoctrineNativeLazyObjectsPass implements CompilerPassInterface
9+
{
10+
public function process(ContainerBuilder $container): void
11+
{
12+
if (PHP_VERSION_ID < 80400) {
13+
return;
14+
}
15+
16+
$configurations = [
17+
'doctrine.orm.configuration',
18+
'doctrine.orm.default_configuration',
19+
];
20+
21+
foreach ($configurations as $configuration) {
22+
if (!$container->hasDefinition($configuration)) {
23+
continue;
24+
}
25+
26+
$definition = $container->getDefinition($configuration);
27+
$definition->addMethodCall('enableNativeLazyObjects', [true]);
28+
}
29+
}
30+
}

webapp/src/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App;
44

5+
use App\DependencyInjection\Compiler\DoctrineNativeLazyObjectsPass;
56
use App\DependencyInjection\Compiler\SetDocLinksPass;
67
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -19,5 +20,6 @@ public function getProjectDir(): string
1920
protected function build(ContainerBuilder $container): void
2021
{
2122
$container->addCompilerPass(new SetDocLinksPass());
23+
$container->addCompilerPass(new DoctrineNativeLazyObjectsPass());
2224
}
2325
}

0 commit comments

Comments
 (0)