aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-05-14 18:42:42 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-06-05 20:51:24 +0200
commit2eed6d3a890958777faa93cf7e1cdf8f77762a88 (patch)
tree737b28e6a70cae68c53c645f729d03316dca14fa
parenta10182f6fb3eecd2b944f4842d8c51e07628049f (diff)
downloadnextcloud-server-2eed6d3a890958777faa93cf7e1cdf8f77762a88.tar.gz
nextcloud-server-2eed6d3a890958777faa93cf7e1cdf8f77762a88.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.php8
-rw-r--r--lib/base.php3
-rw-r--r--lib/private/AppFramework/Utility/SimpleContainer.php4
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 2b08137aff2..9fa6707654a 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -618,6 +618,9 @@ class OC {
}
$loaderEnd = microtime(true);
+ // 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 {