Skip to content

Commit

Permalink
fix: Move storage constructor to specific interface
Browse files Browse the repository at this point in the history
That allows Wrappers to use DI and not care about the constructor

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Sep 16, 2024
1 parent b9fb1db commit 18943e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions apps/files_external/lib/Config/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
use OCA\Files_External\Service\UserStoragesService;
use OCP\Files\Config\IMountProvider;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\Storage\IConstructableStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
use OCP\Files\StorageNotAvailableException;
use OCP\IUser;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;

/**
* Make the old files_external config work with the new public mount config api
Expand Down Expand Up @@ -62,6 +64,9 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user): voi
*/
private function constructStorage(StorageConfig $storageConfig): IStorage {
$class = $storageConfig->getBackend()->getStorageClass();
if (!$class instanceof IConstructableStorage::class) {

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_CLASS, expecting T_VARIABLE or '$' on line 67

Check failure on line 67 in apps/files_external/lib/Config/ConfigAdapter.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

apps/files_external/lib/Config/ConfigAdapter.php:67:49: ParseError: Syntax error, unexpected T_CLASS, expecting T_VARIABLE or '$' on line 67 (see https://psalm.dev/173)
\OCP\Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0' ['class' => $class]);

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_DOUBLE_ARROW, expecting ']' on line 68

Check failure on line 68 in apps/files_external/lib/Config/ConfigAdapter.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

apps/files_external/lib/Config/ConfigAdapter.php:68:150: ParseError: Syntax error, unexpected T_DOUBLE_ARROW, expecting ']' on line 68 (see https://psalm.dev/173)
}
$storage = new $class($storageConfig->getBackendOptions());

// auth mechanism should fire first
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand All @@ -41,7 +42,7 @@
* 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 {

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCP\Files\Storage\IConstructableStorage does not exist
use LocalTempFileTrait;

protected ?Cache $cache = null;
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Files/Storage/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -62,6 +64,9 @@ public function removeStorageWrapper($wrapperName) {
* @return IStorage
*/
public function getInstance(IMountPoint $mountPoint, $class, $arguments) {
if (!($class instanceof IConstructableStorage)) {

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCP\Files\Storage\IConstructableStorage does not exist
\OCP\Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0' ['class' => $class]);

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected T_DOUBLE_ARROW, expecting ']' on line 68
}
return $this->wrap($mountPoint, new $class($arguments));
}

Expand Down
9 changes: 1 addition & 8 deletions lib/public/Files/Storage/IStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@
* 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
Expand Down

0 comments on commit 18943e4

Please sign in to comment.