Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,68 @@ class Api
private $username;
private $password;

/**
* @var array for additional curlSettings in \Sabre\DAV\Client
*/
private $fileManagementConfig;

/**
* @var Api\FileManagement
*/
private $fileManagement;

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()
{
return new Api\FileSharing($this->client);
}

public function fileManagement()
public function fileManagement(): Api\FileManagement
{
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);
}

public function has(string $path): bool
{
return $this->fileManagement()->has($path);
}

/**
* @throws \League\Flysystem\FileNotFoundException
*/
public function delete(string $filePath): bool
{
return new Api\FileManagement($this->host, $this->username, $this->password);
return $this->fileManagement()->delete($filePath);
}

public function getFileContent(string $filePath)
{
if($handler = $this->fileManagement()->get($filePath)){
return $handler->read();
}
return '';

}

}
36 changes: 32 additions & 4 deletions src/Api/FileManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,48 @@

namespace Owncloud\Api;

use League\Flysystem\Adapter\WebDav;
use League\Flysystem\Filesystem;
use Sabre\DAV\Client;

/**
* @author Gustavo Pilla <pilla.gustavo@gmail.com>
*/
class FileManagement extends \League\Flysystem\Filesystem
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 \Sabre\DAV\Client($settings);
$adapter = new \League\Flysystem\Adapter\WebDav($client, 'remote.php/webdav/');
$client = new Client($settings);

/** 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/');
}

parent::__construct($adapter);
}
Expand Down