aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-09-23 15:57:38 +0200
committerGitHub <noreply@github.com>2024-09-23 15:57:38 +0200
commit40b404c5665529ebd661ab032efe24d40ab12df6 (patch)
tree7bbcfefe1097744294fb4d48ed717e6b324eefa5 /lib
parent8927510685f59555cf337866370b572934e41408 (diff)
parentb8ab560bdd1f1f9d80ec6c632323b38a4f007ed7 (diff)
downloadnextcloud-server-40b404c5665529ebd661ab032efe24d40ab12df6.tar.gz
nextcloud-server-40b404c5665529ebd661ab032efe24d40ab12df6.zip
Merge pull request #48111 from nextcloud/fix/move-storage-constructor-to-specific-interface
fix: Move storage constructor to specific interface
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Files/Storage/Common.php3
-rw-r--r--lib/private/Files/Storage/StorageFactory.php5
-rw-r--r--lib/public/Files/Storage/IConstructableStorage.php26
-rw-r--r--lib/public/Files/Storage/IStorage.php9
6 files changed, 36 insertions, 9 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 166d5805bdc..234cc20b4a4 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -428,6 +428,7 @@ return array(
'OCP\\Files\\StorageNotAvailableException' => $baseDir . '/lib/public/Files/StorageNotAvailableException.php',
'OCP\\Files\\StorageTimeoutException' => $baseDir . '/lib/public/Files/StorageTimeoutException.php',
'OCP\\Files\\Storage\\IChunkedFileWrite' => $baseDir . '/lib/public/Files/Storage/IChunkedFileWrite.php',
+ 'OCP\\Files\\Storage\\IConstructableStorage' => $baseDir . '/lib/public/Files/Storage/IConstructableStorage.php',
'OCP\\Files\\Storage\\IDisableEncryptionStorage' => $baseDir . '/lib/public/Files/Storage/IDisableEncryptionStorage.php',
'OCP\\Files\\Storage\\ILockingStorage' => $baseDir . '/lib/public/Files/Storage/ILockingStorage.php',
'OCP\\Files\\Storage\\INotifyStorage' => $baseDir . '/lib/public/Files/Storage/INotifyStorage.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index b455077b958..79186210848 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -461,6 +461,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Files\\StorageNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageNotAvailableException.php',
'OCP\\Files\\StorageTimeoutException' => __DIR__ . '/../../..' . '/lib/public/Files/StorageTimeoutException.php',
'OCP\\Files\\Storage\\IChunkedFileWrite' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IChunkedFileWrite.php',
+ 'OCP\\Files\\Storage\\IConstructableStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IConstructableStorage.php',
'OCP\\Files\\Storage\\IDisableEncryptionStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IDisableEncryptionStorage.php',
'OCP\\Files\\Storage\\ILockingStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/ILockingStorage.php',
'OCP\\Files\\Storage\\INotifyStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/INotifyStorage.php',
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index b6f14321f61..a9721c30d77 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -21,6 +21,7 @@ use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidPathException;
+use OCP\Files\Storage\IConstructableStorage;
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
@@ -41,7 +42,7 @@ use Psr\Log\LoggerInterface;
* Some \OC\Files\Storage\Common methods call functions which are first defined
* in classes which extend it, e.g. $this->stat() .
*/
-abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
+abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, IConstructableStorage {
use LocalTempFileTrait;
protected ?Cache $cache = null;
diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php
index 590425f5b64..f194228d3c8 100644
--- a/lib/private/Files/Storage/StorageFactory.php
+++ b/lib/private/Files/Storage/StorageFactory.php
@@ -8,8 +8,10 @@
namespace OC\Files\Storage;
use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Storage\IConstructableStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
+use Psr\Log\LoggerInterface;
class StorageFactory implements IStorageFactory {
/**
@@ -62,6 +64,9 @@ class StorageFactory implements IStorageFactory {
* @return IStorage
*/
public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
+ if (!($class instanceof IConstructableStorage)) {
+ \OCP\Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0', ['class' => $class]);
+ }
return $this->wrap($mountPoint, new $class($arguments));
}
diff --git a/lib/public/Files/Storage/IConstructableStorage.php b/lib/public/Files/Storage/IConstructableStorage.php
new file mode 100644
index 00000000000..57749fa30fa
--- /dev/null
+++ b/lib/public/Files/Storage/IConstructableStorage.php
@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal Nextcloud classes
+
+namespace OCP\Files\Storage;
+
+/**
+ * Marks a storage as constructable. Allows to pass the storage as a string to a mounpoint and let it build the instance.
+ *
+ * @since 31.0.0
+ */
+interface IConstructableStorage {
+ /**
+ * @param array $parameters is a free form array with the configuration options needed to construct the storage
+ *
+ * @since 31.0.0
+ */
+ public function __construct(array $parameters);
+}
diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php
index 2016c273f91..2368e126bb7 100644
--- a/lib/public/Files/Storage/IStorage.php
+++ b/lib/public/Files/Storage/IStorage.php
@@ -23,17 +23,10 @@ use OCP\Files\InvalidPathException;
* All paths passed to the storage are relative to the storage and should NOT have a leading slash.
*
* @since 9.0.0
+ * @since 31.0.0 Moved the constructor to IConstructableStorage so that wrappers can use DI
*/
interface IStorage {
/**
- * $parameters is a free form array with the configuration options needed to construct the storage
- *
- * @param array $parameters
- * @since 9.0.0
- */
- public function __construct($parameters);
-
- /**
* Get the identifier for the storage,
* the returned id should be the same for every storage object that is created with the same parameters
* and two storage objects with the same id should refer to two storages that display the same files.