Skip to content

Commit

Permalink
refactor(Storage): Align all Storage constructors
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Oct 22, 2024
1 parent 68c73fb commit 09e3855
Show file tree
Hide file tree
Showing 34 changed files with 166 additions and 167 deletions.
8 changes: 4 additions & 4 deletions apps/dav/lib/Storage/PublicOwnerWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class PublicOwnerWrapper extends Wrapper {
private string $owner;

/**
* @param array $arguments ['storage' => $storage, 'owner' => $owner]
* @param array $parameters ['storage' => $storage, 'owner' => $owner]
*
* $storage: The storage the permissions mask should be applied on
* $owner: The owner to use in case no owner is found
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->owner = $arguments['owner'];
public function __construct(array $parameters) {
parent::__construct($parameters);
$this->owner = $parameters['owner'];
}

public function getOwner(string $path): string|false {
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/Storage/PublicShareWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PublicShareWrapper extends Wrapper implements ISharedStorage {
private IShare $share;

/**
* @param array $arguments ['storage' => $storage, 'share' => $share]
* @param array $parameters ['storage' => $storage, 'share' => $share]
*
* $storage: The storage the permissions mask should be applied on
* $share: The share to use in case no share is found
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->share = $arguments['share'];
public function __construct(array $parameters) {
parent::__construct($parameters);
$this->share = $parameters['share'];
}

public function getShare(): IShare {
Expand Down
9 changes: 4 additions & 5 deletions apps/files_external/lib/Lib/SessionStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
* Wrap Storage in PermissionsMask for session ephemeral use
*/
class SessionStorageWrapper extends PermissionsMask {

/**
* @param array $arguments ['storage' => $storage]
* @param array $parameters ['storage' => $storage]
*/
public function __construct($arguments) {
public function __construct(array $parameters) {
// disable sharing permission
$arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE;
parent::__construct($arguments);
$parameters['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE;
parent::__construct($parameters);
}
}
2 changes: 1 addition & 1 deletion apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function needsPartFile(): bool {
private ?bool $versioningEnabled = null;
private ICache $memCache;

public function __construct($parameters) {
public function __construct(array $parameters) {
parent::__construct($parameters);
$this->parseParams($parameters);
$this->id = 'amazon::external::' . md5($this->params['hostname'] . ':' . $this->params['bucket'] . ':' . $this->params['key']);
Expand Down
24 changes: 12 additions & 12 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ class FTP extends Common {
/** @var FtpConnection|null */
private $connection;

public function __construct($params) {
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
$this->host = $params['host'];
$this->username = $params['user'];
$this->password = $params['password'];
if (isset($params['secure'])) {
if (is_string($params['secure'])) {
$this->secure = ($params['secure'] === 'true');
public function __construct(array $parameters) {
if (isset($parameters['host']) && isset($parameters['user']) && isset($parameters['password'])) {
$this->host = $parameters['host'];
$this->username = $parameters['user'];
$this->password = $parameters['password'];
if (isset($parameters['secure'])) {
if (is_string($parameters['secure'])) {
$this->secure = ($parameters['secure'] === 'true');
} else {
$this->secure = (bool)$params['secure'];
$this->secure = (bool)$parameters['secure'];
}
} else {
$this->secure = false;
}
$this->root = isset($params['root']) ? '/' . ltrim($params['root']) : '/';
$this->port = $params['port'] ?? 21;
$this->utf8Mode = isset($params['utf8']) && $params['utf8'];
$this->root = isset($parameters['root']) ? '/' . ltrim($parameters['root']) : '/';
$this->port = $parameters['port'] ?? 21;
$this->utf8Mode = isset($parameters['utf8']) && $parameters['utf8'];
} else {
throw new \Exception('Creating ' . self::class . ' storage failed, required parameters not set');
}
Expand Down
20 changes: 10 additions & 10 deletions apps/files_external/lib/Lib/Storage/OwnCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
class OwnCloud extends DAV implements IDisableEncryptionStorage {
public const OC_URL_SUFFIX = 'remote.php/webdav';

public function __construct($params) {
public function __construct(array $parameters) {
// extract context path from host if specified
// (owncloud install path on host)
$host = $params['host'];
$host = $parameters['host'];
// strip protocol
if (substr($host, 0, 8) === 'https://') {
$host = substr($host, 8);
$params['secure'] = true;
$parameters['secure'] = true;
} elseif (substr($host, 0, 7) === 'http://') {
$host = substr($host, 7);
$params['secure'] = false;
$parameters['secure'] = false;
}
$contextPath = '';
$hostSlashPos = strpos($host, '/');
Expand All @@ -43,17 +43,17 @@ public function __construct($params) {
$contextPath .= '/';
}

if (isset($params['root'])) {
$root = '/' . ltrim($params['root'], '/');
if (isset($parameters['root'])) {
$root = '/' . ltrim($parameters['root'], '/');
} else {
$root = '/';
}

$params['host'] = $host;
$params['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
$params['authType'] = Client::AUTH_BASIC;
$parameters['host'] = $host;
$parameters['root'] = $contextPath . self::OC_URL_SUFFIX . $root;
$parameters['authType'] = Client::AUTH_BASIC;

parent::__construct($params);
parent::__construct($parameters);
}

public function needsPartFile(): bool {
Expand Down
18 changes: 9 additions & 9 deletions apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ private function splitHost(string $host): array {
}
}

public function __construct($params) {
public function __construct(array $parameters) {
// Register sftp://
Stream::register();

$parsedHost = $this->splitHost($params['host']);
$parsedHost = $this->splitHost($parameters['host']);

$this->host = $parsedHost[0];
$this->port = $parsedHost[1];

if (!isset($params['user'])) {
if (!isset($parameters['user'])) {
throw new \UnexpectedValueException('no authentication parameters specified');
}
$this->user = $params['user'];
$this->user = $parameters['user'];

if (isset($params['public_key_auth'])) {
$this->auth[] = $params['public_key_auth'];
if (isset($parameters['public_key_auth'])) {
$this->auth[] = $parameters['public_key_auth'];
}
if (isset($params['password']) && $params['password'] !== '') {
$this->auth[] = $params['password'];
if (isset($parameters['password']) && $parameters['password'] !== '') {
$this->auth[] = $parameters['password'];
}

if ($this->auth === []) {
throw new \UnexpectedValueException('no authentication parameters specified');
}

$this->root
= isset($params['root']) ? $this->cleanPath($params['root']) : '/';
= isset($parameters['root']) ? $this->cleanPath($parameters['root']) : '/';

$this->root = '/' . ltrim($this->root, '/');
$this->root = rtrim($this->root, '/') . '/';
Expand Down
40 changes: 20 additions & 20 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,55 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $checkAcl;

public function __construct($params) {
if (!isset($params['host'])) {
public function __construct(array $parameters) {
if (!isset($parameters['host'])) {
throw new \Exception('Invalid configuration, no host provided');
}

if (isset($params['auth'])) {
$auth = $params['auth'];
} elseif (isset($params['user']) && isset($params['password']) && isset($params['share'])) {
[$workgroup, $user] = $this->splitUser($params['user']);
$auth = new BasicAuth($user, $workgroup, $params['password']);
if (isset($parameters['auth'])) {
$auth = $parameters['auth'];
} elseif (isset($parameters['user']) && isset($parameters['password']) && isset($parameters['share'])) {
[$workgroup, $user] = $this->splitUser($parameters['user']);
$auth = new BasicAuth($user, $workgroup, $parameters['password']);
} else {
throw new \Exception('Invalid configuration, no credentials provided');
}

if (isset($params['logger'])) {
if (!$params['logger'] instanceof LoggerInterface) {
if (isset($parameters['logger'])) {
if (!$parameters['logger'] instanceof LoggerInterface) {
throw new \Exception(
'Invalid logger. Got '
. get_class($params['logger'])
. get_class($parameters['logger'])
. ' Expected ' . LoggerInterface::class
);
}
$this->logger = $params['logger'];
$this->logger = $parameters['logger'];
} else {
$this->logger = \OCP\Server::get(LoggerInterface::class);
}

$options = new Options();
if (isset($params['timeout'])) {
$timeout = (int)$params['timeout'];
if (isset($parameters['timeout'])) {
$timeout = (int)$parameters['timeout'];
if ($timeout > 0) {
$options->setTimeout($timeout);
}
}
$system = \OCP\Server::get(SystemBridge::class);
$serverFactory = new ServerFactory($options, $system);
$this->server = $serverFactory->createServer($params['host'], $auth);
$this->share = $this->server->getShare(trim($params['share'], '/'));
$this->server = $serverFactory->createServer($parameters['host'], $auth);
$this->share = $this->server->getShare(trim($parameters['share'], '/'));

$this->root = $params['root'] ?? '/';
$this->root = $parameters['root'] ?? '/';
$this->root = '/' . ltrim($this->root, '/');
$this->root = rtrim($this->root, '/') . '/';

$this->showHidden = isset($params['show_hidden']) && $params['show_hidden'];
$this->caseSensitive = (bool)($params['case_sensitive'] ?? true);
$this->checkAcl = isset($params['check_acl']) && $params['check_acl'];
$this->showHidden = isset($parameters['show_hidden']) && $parameters['show_hidden'];
$this->caseSensitive = (bool)($parameters['case_sensitive'] ?? true);
$this->checkAcl = isset($parameters['check_acl']) && $parameters['check_acl'];

$this->statCache = new CappedMemoryCache();
parent::__construct($params);
parent::__construct($parameters);
}

private function splitUser(string $user): array {
Expand Down
42 changes: 21 additions & 21 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,44 @@ private function doesObjectExist(string $path): bool {
return $this->fetchObject($path) !== false;
}

public function __construct($params) {
if ((empty($params['key']) and empty($params['password']))
or (empty($params['user']) && empty($params['userid'])) or empty($params['bucket'])
or empty($params['region'])
public function __construct(array $parameters) {
if ((empty($parameters['key']) and empty($parameters['password']))
or (empty($parameters['user']) && empty($parameters['userid'])) or empty($parameters['bucket'])
or empty($parameters['region'])
) {
throw new StorageBadConfigException('API Key or password, Login, Bucket and Region have to be configured.');
}

$user = $params['user'];
$this->id = 'swift::' . $user . md5($params['bucket']);
$user = $parameters['user'];
$this->id = 'swift::' . $user . md5($parameters['bucket']);

$bucketUrl = new Uri($params['bucket']);
$bucketUrl = new Uri($parameters['bucket']);
if ($bucketUrl->getHost()) {
$params['bucket'] = basename($bucketUrl->getPath());
$params['endpoint_url'] = (string)$bucketUrl->withPath(dirname($bucketUrl->getPath()));
$parameters['bucket'] = basename($bucketUrl->getPath());
$parameters['endpoint_url'] = (string)$bucketUrl->withPath(dirname($bucketUrl->getPath()));
}

if (empty($params['url'])) {
$params['url'] = 'https://identity.api.rackspacecloud.com/v2.0/';
if (empty($parameters['url'])) {
$parameters['url'] = 'https://identity.api.rackspacecloud.com/v2.0/';
}

if (empty($params['service_name'])) {
$params['service_name'] = 'cloudFiles';
if (empty($parameters['service_name'])) {
$parameters['service_name'] = 'cloudFiles';
}

$params['autocreate'] = true;
$parameters['autocreate'] = true;

if (isset($params['domain'])) {
$params['user'] = [
'name' => $params['user'],
'password' => $params['password'],
if (isset($parameters['domain'])) {
$parameters['user'] = [
'name' => $parameters['user'],
'password' => $parameters['password'],
'domain' => [
'name' => $params['domain'],
'name' => $parameters['domain'],
]
];
}

$this->params = $params;
$this->params = $parameters;
// FIXME: private class...
$this->objectCache = new CappedMemoryCache();
$this->connectionFactory = new SwiftFactory(
Expand All @@ -165,7 +165,7 @@ public function __construct($params) {
\OC::$server->get(LoggerInterface::class)
);
$this->objectStore = new \OC\Files\ObjectStore\Swift($this->params, $this->connectionFactory);
$this->bucket = $params['bucket'];
$this->bucket = $parameters['bucket'];
$this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class);
}

Expand Down
14 changes: 7 additions & 7 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage
*/
protected $storage;

public function __construct($arguments) {
$this->ownerView = $arguments['ownerView'];
public function __construct(array $parameters) {
$this->ownerView = $parameters['ownerView'];
$this->logger = \OC::$server->get(LoggerInterface::class);

$this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares'];
$this->superShare = $parameters['superShare'];
$this->groupedShares = $parameters['groupedShares'];

$this->user = $arguments['user'];
if (isset($arguments['sharingDisabledForUser'])) {
$this->sharingDisabledForUser = $arguments['sharingDisabledForUser'];
$this->user = $parameters['user'];
if (isset($parameters['sharingDisabledForUser'])) {
$this->sharingDisabledForUser = $parameters['sharingDisabledForUser'];
} else {
$this->sharingDisabledForUser = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage {
private string $internalId;

/**
* @param array $params
* @param array $parameters
* @throws \Exception
*/
public function __construct($params) {
if (!isset($params['internal-id'])) {
public function __construct(array $parameters) {
if (!isset($parameters['internal-id'])) {
throw new \Exception('missing id in parameters');
}
$this->internalId = (string)$params['internal-id'];
parent::__construct($params);
$this->internalId = (string)$parameters['internal-id'];
parent::__construct($parameters);
}

public function getId(): string {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/ObjectStore/Azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Azure implements IObjectStore {
/**
* @param array $parameters
*/
public function __construct($parameters) {
public function __construct(array $parameters) {
$this->containerName = $parameters['container'];
$this->accountName = $parameters['account_name'];
$this->accountKey = $parameters['account_key'];
Expand Down
Loading

0 comments on commit 09e3855

Please sign in to comment.