Skip to content

Commit

Permalink
Use PSR-4 and public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored and PVince81 committed Nov 21, 2016
1 parent 8fb89a8 commit 82968d5
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 26 deletions.
17 changes: 1 addition & 16 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
<?php

$l = \OC::$server->getL10N('files_external_ftp');
$app = new \OCA\Files_external_ftp\AppInfo\Application();

if (!class_exists('OC_Mount_Config')) {
OC_App::loadApp('files_external');
}
OC_Mount_Config::registerBackend('\OCA\Files_External_FTP\FTP', [
'backend' => (string)$l->t('FTP (Fly)'),
'priority' => 100,
'configuration' => [
'host' => (string)$l->t('hostname'),
'username' => (string)$l->t('Username'),
'password' => (string)$l->t('Password'),
'root' => '&' . $l->t('Remote subfolder'),
'secure' => '!' . $l->t('Secure ftps://'),
'port' => '&' . $l->t('Port'),
],
]);
5 changes: 4 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</types>

<dependencies>
<owncloud min-version="9.1" max-version="9.2"/>
<owncloud min-version="9.2" max-version="9.2"/>
</dependencies>
<website>https://github.com/owncloud/files_external_ftp/</website>
<bugs>https://github.com/owncloud/files_external_ftp/issues</bugs>
<repository type="git">https://github.com/owncloud/files_external_ftp.git</repository>
</info>
56 changes: 56 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Files_external_ftp\AppInfo;

use \OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use \OCP\IContainer;
use \OCA\Files_External\Service\BackendService;
use \OCA\Files_External\Lib\Config\IBackendProvider;

/**
* @package OCA\Files_External_FTP\AppInfo
*/
class Application extends App implements IBackendProvider {

public function __construct(array $urlParams = array()) {
parent::__construct('files_external_ftp', $urlParams);

$container = $this->getContainer();

$backendService = $container->getServer()->getStoragesBackendService();
$backendService->registerBackendProvider($this);
}

/**
* @{inheritdoc}
*/
public function getBackends() {
$container = $this->getContainer();

$backends = [
$container->query('OCA\Files_external_ftp\Backend\FTP'),
];

return $backends;
}
}
53 changes: 53 additions & 0 deletions lib/Backend/FTP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Files_external_ftp\Backend;

use \OCP\IL10N;
use \OCA\Files_External\Lib\Backend\Backend;
use \OCA\Files_External\Lib\DefinitionParameter;
use \OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCA\Files_External\Service\BackendService;

use \OCA\Files_External\Lib\Auth\Password\Password;

class FTP extends Backend {

public function __construct(IL10N $l, Password $legacyAuth) {
$this
->setIdentifier('ftp')
->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat
->setStorageClass('\OCA\Files_external_ftp\Storage\FTP')
->setText($l->t('FTP (Fly)'))
->addParameters([
(new DefinitionParameter('host', $l->t('Host'))),
(new DefinitionParameter('root', $l->t('Root')))
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
(new DefinitionParameter('port', $l->t('Port')))
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
(new DefinitionParameter('secure', $l->t('Secure ftps://')))
->setType(DefinitionParameter::VALUE_BOOLEAN),
])
->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
->setLegacyAuthMechanism($legacyAuth);
}

}
2 changes: 1 addition & 1 deletion lib/adapter.php → lib/Storage/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_External_FTP;
namespace OCA\Files_external_ftp\Storage;

use League\Flysystem\Adapter\Ftp as FtpAdapter;
use League\Flysystem\AdapterInterface;
Expand Down
10 changes: 5 additions & 5 deletions lib/ftp.php → lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_External_FTP;
namespace OCA\Files_external_ftp\Storage;

use League\Flysystem\FileNotFoundException;
use OC\Files\Storage\Flysystem;
Expand All @@ -39,9 +39,9 @@ class FTP extends Flysystem {
private $adapter;

public function __construct($params) {
if (isset($params['host']) && isset($params['username']) && isset($params['password'])) {
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
$this->host = $params['host'];
$this->username = $params['username'];
$this->username = $params['user'];
$this->password = $params['password'];
if (isset($params['secure'])) {
if (is_string($params['secure'])) {
Expand All @@ -57,14 +57,14 @@ public function __construct($params) {

$this->adapter = new Adapter([
'host' => $params['host'],
'username' => $params['username'],
'username' => $params['user'],
'password' => $params['password'],
'port' => $this->port,
'ssl' => $this->secure
]);
$this->buildFlySystem($this->adapter);
} else {
throw new \Exception('Creating \OCA\Files_External_FTP\FTP storage failed');
throw new \Exception('Creating \OCA\Files_external_ftp\FTP storage failed');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"host": "localhost",
"username": "test",
"user": "test",
"password": "test"
}
4 changes: 2 additions & 2 deletions tests/ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
*/

namespace Test\Files_External_FTP;
namespace Test\Files_external_ftp;

use Test\Files\Storage\Storage;

Expand All @@ -36,7 +36,7 @@ protected function setUp() {

$this->config = json_decode(file_get_contents('./config.json'), true);
$this->config['root'] = $this->getUniqueID();
$this->instance = new \OCA\Files_External_FTP\FTP($this->config);
$this->instance = new \OCA\Files_external_ftp\Storage\FTP($this->config);
$this->instance->mkdir('');
}

Expand Down

0 comments on commit 82968d5

Please sign in to comment.