use OC\Files\Storage\DAV;
use OC\ForbiddenException;
use OCA\Files_Sharing\ISharedStorage;
+use OCA\Files_Sharing\External\Manager as ExternalShareManager;
use OCP\AppFramework\Http;
use OCP\Constants;
use OCP\Federation\ICloudId;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\LocalServerException;
+use OCP\Http\Client\IClientService;
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage {
/** @var ICloudId */
/** @var bool */
private $updateChecked = false;
- /**
- * @var \OCA\Files_Sharing\External\Manager
- */
+ /** @var ExternalShareManager */
private $manager;
+ /**
+ * @param array{HttpClientService: IClientService, manager: ExternalShareManager, cloudId: ICloudId, mountpoint: string, token: string, password: ?string}|array $options
+ */
public function __construct($options) {
$this->memcacheFactory = \OC::$server->getMemCacheFactory();
$this->httpClient = $options['HttpClientService'];
return $this->watcher;
}
- public function getRemoteUser() {
+ public function getRemoteUser(): string {
return $this->cloudId->getUser();
}
- public function getRemote() {
+ public function getRemote(): string {
return $this->cloudId->getRemote();
}
- public function getMountPoint() {
+ public function getMountPoint(): string {
return $this->mountPoint;
}
- public function getToken() {
+ public function getToken(): string {
return $this->token;
}
- public function getPassword() {
+ public function getPassword(): ?string {
return $this->password;
}
/**
- * @brief get id of the mount point
+ * Get id of the mount point.
* @return string
*/
public function getId() {
}
/**
- * check if a file or folder has been updated since $time
+ * Check if a file or folder has been updated since $time
*
* @param string $path
* @param int $time
}
/**
- * check if the configured remote is a valid federated share provider
+ * Check if the configured remote is a valid federated share provider
*
* @return bool
*/
- protected function testRemote() {
+ protected function testRemote(): bool {
try {
return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
|| $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
}
}
- /**
- * @param string $url
- * @return bool
- */
- private function testRemoteUrl($url) {
+ private function testRemoteUrl(string $url): bool {
$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
if ($cache->hasKey($url)) {
return (bool)$cache->get($url);
}
/**
- * Whether the remote is an ownCloud/Nextcloud, used since some sharing features are not
- * standardized. Let's use this to detect whether to use it.
+ * Check whether the remote is an ownCloud/Nextcloud. This is needed since some sharing
+ * features are not standardized.
*
- * @return bool
+ * @throws LocalServerException
*/
- public function remoteIsOwnCloud() {
+ public function remoteIsOwnCloud(): bool {
if (defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
return false;
}
}
/**
- * translate OCM Permissions to Nextcloud permissions
+ * Translate OCM Permissions to Nextcloud permissions
*
* @param string $ocmPermissions json encoded OCM permissions
* @param string $path path to file
* @return int
*/
- protected function ocmPermissions2ncPermissions($ocmPermissions, $path) {
+ protected function ocmPermissions2ncPermissions(string $ocmPermissions, string $path): int {
try {
$ocmPermissions = json_decode($ocmPermissions);
$ncPermissions = 0;
}
/**
- * calculate default permissions in case no permissions are provided
- *
- * @param $path
- * @return int
+ * Calculate the default permissions in case no permissions are provided
*/
- protected function getDefaultPermissions($path) {
+ protected function getDefaultPermissions(string $path): int {
if ($this->is_dir($path)) {
$permissions = Constants::PERMISSION_ALL;
} else {