From 10efec246de432e27a594d5b237bdef4d8e465eb Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 22 Jul 2017 12:48:22 +0200 Subject: [PATCH] Move over Config Signed-off-by: Roeland Jago Douma --- apps/testing/appinfo/routes.php | 36 +++++-------- .../ConfigController.php} | 50 +++++++++---------- 2 files changed, 36 insertions(+), 50 deletions(-) rename apps/testing/lib/{Config.php => Controller/ConfigController.php} (55%) diff --git a/apps/testing/appinfo/routes.php b/apps/testing/appinfo/routes.php index d45cfe00ec..aa32e4583c 100644 --- a/apps/testing/appinfo/routes.php +++ b/apps/testing/appinfo/routes.php @@ -22,16 +22,10 @@ namespace OCA\Testing\AppInfo; -use OCA\Testing\Config; use OCA\Testing\Locking\Provisioning; use OCP\API; use OCP\AppFramework\App; -$config = new Config( - \OC::$server->getConfig(), - \OC::$server->getRequest() -); - $app = new App('testing'); $app->registerRoutes( $this, @@ -47,26 +41,22 @@ $app->registerRoutes( 'url' => '/anonProtected', 'verb' => 'GET', ], - ] + ], + 'ocs' => [ + [ + 'name' => 'Config#setAppValue', + 'url' => '/api/v1/app/{appid}/{configkey}', + 'verb' => 'POST', + ], + [ + 'name' => 'Config#deleteAppValue', + 'url' => '/api/v1/app/{appid}/{configkey}', + 'verb' => 'DELETE', + ], + ], ] ); -API::register( - 'post', - '/apps/testing/api/v1/app/{appid}/{configkey}', - [$config, 'setAppValue'], - 'testing', - API::ADMIN_AUTH -); - -API::register( - 'delete', - '/apps/testing/api/v1/app/{appid}/{configkey}', - [$config, 'deleteAppValue'], - 'testing', - API::ADMIN_AUTH -); - $locking = new Provisioning( \OC::$server->getLockingProvider(), \OC::$server->getDatabaseConnection(), diff --git a/apps/testing/lib/Config.php b/apps/testing/lib/Controller/ConfigController.php similarity index 55% rename from apps/testing/lib/Config.php rename to apps/testing/lib/Controller/ConfigController.php index 6cdd28d4b3..7b3e73ab17 100644 --- a/apps/testing/lib/Config.php +++ b/apps/testing/lib/Controller/ConfigController.php @@ -20,52 +20,48 @@ * */ -namespace OCA\Testing; +namespace OCA\Testing\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IRequest; -class Config { +class ConfigController extends OCSController { /** @var IConfig */ private $config; - /** @var IRequest */ - private $request; - /** - * @param IConfig $config + * @param string $appName * @param IRequest $request + * @param IConfig $config */ - public function __construct(IConfig $config, IRequest $request) { + public function __construct($appName, + IRequest $request, + IConfig $config) { + parent::__construct($appName, $request); $this->config = $config; - $this->request = $request; } /** - * @param array $parameters - * @return \OC_OCS_Result + * @param string $appid + * @param string $configkey + * @param string $value + * @return DataResponse */ - public function setAppValue($parameters) { - $app = $parameters['appid']; - $configKey = $parameters['configkey']; - - $value = $this->request->getParam('value'); - $this->config->setAppValue($app, $configKey, $value); - - return new \OC_OCS_Result(); + public function setAppValue($appid, $configkey, $value) { + $this->config->setAppValue($appid, $configkey, $value); + return new DataResponse(); } /** - * @param array $parameters - * @return \OC_OCS_Result + * @param string $appid + * @param string $configkey + * @return DataResponse */ - public function deleteAppValue($parameters) { - $app = $parameters['appid']; - $configKey = $parameters['configkey']; - - $this->config->deleteAppValue($app, $configKey); - - return new \OC_OCS_Result(); + public function deleteAppValue($appid, $configkey) { + $this->config->deleteAppValue($appid, $configkey); + return new DataResponse(); } }