diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-05-14 18:42:42 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-05-16 17:04:43 +0200 |
commit | ad34a7c99174316b5fe09b60a72af88360c007e9 (patch) | |
tree | 3c2b3dab7b54bbd508fc48c34adc362c27835b02 | |
parent | abc98a79b17103a2d5477d9e73c55a6f01a0a6f3 (diff) | |
download | nextcloud-server-ad34a7c99174316b5fe09b60a72af88360c007e9.tar.gz nextcloud-server-ad34a7c99174316b5fe09b60a72af88360c007e9.zip |
feat: Add a configuration toggle for lazy objects in DI
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | config/config.sample.php | 8 | ||||
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/private/AppFramework/Utility/SimpleContainer.php | 4 |
3 files changed, 14 insertions, 1 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index ac15d9f5aeb..da87edff575 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2743,4 +2743,12 @@ $CONFIG = [ * Defaults to true. */ 'files.trash.delete' => true, + +/** + * Enable lazy objects feature from PHP 8.4 to be used in the Dependency Injection. + * Should improve performances by avoiding buiding unused objects. + * + * Defaults to false. + */ +'enable_lazy_objects' => false, ]; diff --git a/lib/base.php b/lib/base.php index b01aae20ec9..5aca4c4818d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -631,6 +631,9 @@ class OC { exit(); } + // Enable lazy loading if activated + \OC\AppFramework\Utility\SimpleContainer::$useLazyObjects = (bool)self::$config->getValue('enable_lazy_objects'); + // setup the basic server self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); self::$server->boot(); diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 200d5c078a8..481c12cc708 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -24,6 +24,8 @@ use function class_exists; * SimpleContainer is a simple implementation of a container on basis of Pimple */ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { + public static bool $useLazyObjects = false; + private Container $container; public function __construct() { @@ -58,7 +60,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { /* No constructor, return a instance directly */ return $class->newInstance(); } - if (PHP_VERSION_ID >= 80400) { + if (PHP_VERSION_ID >= 80400 && self::$useLazyObjects) { /* For PHP>=8.4, use a lazy ghost to delay constructor and dependency resolving */ /** @psalm-suppress UndefinedMethod */ return $class->newLazyGhost(function (object $object) use ($constructor): void { |