From 6ed4ad4c8cf1169f03edad9a18328b18619bb26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 22 Sep 2025 23:52:31 +0200 Subject: [PATCH] Use native lazy objects for doctrine when on PHP8.4 --- config/packages/doctrine.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 config/packages/doctrine.php diff --git a/config/packages/doctrine.php b/config/packages/doctrine.php new file mode 100644 index 00000000..47584ed7 --- /dev/null +++ b/config/packages/doctrine.php @@ -0,0 +1,33 @@ +. + */ + +declare(strict_types=1); + +/** + * This class extends the default doctrine ORM configuration to enable native lazy objects on PHP 8.4+. + * We have to do this in a PHP file, because the yaml file does not support conditionals on PHP version. + */ + +return static function(\Symfony\Config\DoctrineConfig $doctrine) { + //On PHP 8.4+ we can use native lazy objects, which are much more efficient than proxies. + if (PHP_VERSION_ID >= 80400) { + $doctrine->orm()->enableNativeLazyObjects(true); + } +};