From e7bd1a8fb438cd6062ad13141fc9af25e154a5df Mon Sep 17 00:00:00 2001 From: Uldis Nelsons Date: Mon, 7 Jun 2021 10:50:36 +0300 Subject: [PATCH 1/5] Update Api.php --- src/Api.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Api.php b/src/Api.php index 748f9d7..0f17dff 100644 --- a/src/Api.php +++ b/src/Api.php @@ -9,15 +9,22 @@ class Api private $username; private $password; + /** + * @var array for additional curlSettings in \Sabre\DAV\Client + */ + private $fileManagementConfig; + public function __construct($host, $username, $password, $config = array()) { $this->host = $host; $this->username = $username; $this->password = $password; - + $this->fileManagementConfig = $config['fileManagementConfig']; $config['base_url'] = $host; $config['defaults']['auth'] = [$username, $password]; $this->client = new Client($config); + + } public function fileSharing() @@ -27,6 +34,6 @@ public function fileSharing() public function fileManagement() { - return new Api\FileManagement($this->host, $this->username, $this->password); + return new Api\FileManagement($this->host, $this->username, $this->password,$this->fileManagementConfig); } } From f75ecebdfeefe7aaf7a4477cc5f1b1a86107dcfa Mon Sep 17 00:00:00 2001 From: Uldis Nelsons Date: Mon, 7 Jun 2021 10:51:09 +0300 Subject: [PATCH 2/5] Update FileManagement.php --- src/Api/FileManagement.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Api/FileManagement.php b/src/Api/FileManagement.php index dd6f5e0..0457694 100644 --- a/src/Api/FileManagement.php +++ b/src/Api/FileManagement.php @@ -15,6 +15,9 @@ public function __construct($host, $username, $password, $settings = array()) $settings['password'] = $password; $client = new \Sabre\DAV\Client($settings); + foreach($settings['curlSettings'] as $curlSettingName => $curlSettingValue) { + $client->addCurlSetting($curlSettingName, $curlSettingValue); + } $adapter = new \League\Flysystem\Adapter\WebDav($client, 'remote.php/webdav/'); parent::__construct($adapter); From 27aa0ef8e1f4fb83357c8e90f1744bebd740893b Mon Sep 17 00:00:00 2001 From: uldisn Date: Mon, 14 Jun 2021 11:10:47 +0300 Subject: [PATCH 3/5] Added methods listContents,delete,getFileContent Signed-off-by: uldisn --- src/Api.php | 36 ++++++++++++++++++++++++++++++++++-- src/Api/FileManagement.php | 10 +++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Api.php b/src/Api.php index 0f17dff..49a1314 100644 --- a/src/Api.php +++ b/src/Api.php @@ -14,6 +14,11 @@ class Api */ private $fileManagementConfig; + /** + * @var Api\FileManagement + */ + private $fileManagement; + public function __construct($host, $username, $password, $config = array()) { $this->host = $host; @@ -32,8 +37,35 @@ public function fileSharing() return new Api\FileSharing($this->client); } - public function fileManagement() + public function fileManagement(): Api\FileManagement { - return new Api\FileManagement($this->host, $this->username, $this->password,$this->fileManagementConfig); + if($this->fileManagement){ + return $this->fileManagement; + } + return $this->fileManagement = new Api\FileManagement($this->host, $this->username, $this->password, $this->fileManagementConfig); + } + + public function listContents(string $path): array + { + return $this->fileManagement()->listContents($path); + } + + /** + * @throws \League\Flysystem\FileNotFoundException + */ + public function delete(string $filePath): bool + { + return $this->fileManagement()->delete($filePath); + } + + public function getFileContent(string $filePath) + { + if($handler = $this->fileManagement()->get($filePath)){ + return $handler->read(); + } + return ''; + + } + } diff --git a/src/Api/FileManagement.php b/src/Api/FileManagement.php index 0457694..1ae0d2c 100644 --- a/src/Api/FileManagement.php +++ b/src/Api/FileManagement.php @@ -2,10 +2,14 @@ namespace Owncloud\Api; +use League\Flysystem\Adapter\WebDav; +use League\Flysystem\Filesystem; +use Sabre\DAV\Client; + /** * @author Gustavo Pilla */ -class FileManagement extends \League\Flysystem\Filesystem +class FileManagement extends Filesystem { public function __construct($host, $username, $password, $settings = array()) @@ -14,11 +18,11 @@ public function __construct($host, $username, $password, $settings = array()) $settings['userName'] = $username; $settings['password'] = $password; - $client = new \Sabre\DAV\Client($settings); + $client = new Client($settings); foreach($settings['curlSettings'] as $curlSettingName => $curlSettingValue) { $client->addCurlSetting($curlSettingName, $curlSettingValue); } - $adapter = new \League\Flysystem\Adapter\WebDav($client, 'remote.php/webdav/'); + $adapter = new WebDav($client, 'remote.php/webdav/'); parent::__construct($adapter); } From 439f244884ab2927451670403a3571c43adaac94 Mon Sep 17 00:00:00 2001 From: uldisn Date: Fri, 18 Jun 2021 10:23:13 +0300 Subject: [PATCH 4/5] Added has() method Signed-off-by: uldisn --- src/Api.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Api.php b/src/Api.php index 49a1314..7a1f903 100644 --- a/src/Api.php +++ b/src/Api.php @@ -51,6 +51,11 @@ public function listContents(string $path): array return $this->fileManagement()->listContents($path); } + public function has(string $path): bool + { + return $this->fileManagement()->has($path); + } + /** * @throws \League\Flysystem\FileNotFoundException */ From 7c8ecc6eee6cdd1b0ce637b75d4dd57143e7dd59 Mon Sep 17 00:00:00 2001 From: uldisn Date: Tue, 7 Dec 2021 14:56:21 +0200 Subject: [PATCH 5/5] Added additional settings for curl and pathRemoteWebDav Signed-off-by: uldisn --- src/Api/FileManagement.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Api/FileManagement.php b/src/Api/FileManagement.php index 1ae0d2c..2d0e2ab 100644 --- a/src/Api/FileManagement.php +++ b/src/Api/FileManagement.php @@ -12,17 +12,38 @@ class FileManagement extends Filesystem { - public function __construct($host, $username, $password, $settings = array()) + /** + * @param $host string + * @param $username string + * @param $password string + * @param $settings array ['curlSettings' => [],'pathRemoteWebDav' => 'wweebb'] + */ + public function __construct( + $host, + $username, + $password, + $settings = array() + ) { $settings['baseUri'] = $host; $settings['userName'] = $username; $settings['password'] = $password; $client = new Client($settings); - foreach($settings['curlSettings'] as $curlSettingName => $curlSettingValue) { - $client->addCurlSetting($curlSettingName, $curlSettingValue); + + /** load curl settings */ + if (isset($settings['curlSettings'])) { + foreach ($settings['curlSettings'] as $curlSettingName => $curlSettingValue) { + $client->addCurlSetting($curlSettingName, $curlSettingValue); + } + } + + /** set from setting WebDav path */ + if (isset($settings['pathRemoteWebDav'])) { + $adapter = new WebDav($client, $settings['pathRemoteWebDav']); + } else { + $adapter = new WebDav($client, 'remote.php/webdav/'); } - $adapter = new WebDav($client, 'remote.php/webdav/'); parent::__construct($adapter); }