diff options
author | sualko <klaus@jsxc.org> | 2018-10-28 16:24:42 +0300 |
---|---|---|
committer | sualko <klaus@jsxc.org> | 2018-10-28 16:24:42 +0300 |
commit | e9edc1224ba15589ae5e7ba9717eef57d8dd11c8 (patch) | |
tree | 30f655a02411f9b40ea57f7cc1bf1e2d26890514 | |
parent | 9a5c415edf52611d59bf306ecd99aff8d86f43f3 (diff) |
use own config class
-rw-r--r-- | appinfo/Application.php | 10 | ||||
-rw-r--r-- | lib/Config.php | 34 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 34 |
3 files changed, 49 insertions, 29 deletions
diff --git a/appinfo/Application.php b/appinfo/Application.php index 72591f3..fed6193 100644 --- a/appinfo/Application.php +++ b/appinfo/Application.php @@ -1,6 +1,7 @@ <?php namespace OCA\Piwik\AppInfo; +use OCA\Piwik\Config; use OCA\Piwik\Controller\SettingsController; use OCA\Piwik\Migration\Settings as SettingsMigration; use OCP\AppFramework\App; @@ -15,6 +16,13 @@ class Application extends App $container = $this->getContainer(); + $container->registerService('OCA\Piwik\Config', function (IContainer $c) { + return new Config( + $c->query('AppName'), + $c->query('OCP\IConfig') + ); + }); + /** * Controllers */ @@ -22,7 +30,7 @@ class Application extends App return new SettingsController( $c->query('AppName'), $c->query('Request'), - $c->query('OCP\IConfig') + $c->query('OCA\Piwik\Config') ); }); diff --git a/lib/Config.php b/lib/Config.php new file mode 100644 index 0000000..0889d41 --- /dev/null +++ b/lib/Config.php @@ -0,0 +1,34 @@ +<?php +namespace OCA\Piwik; + +use OCP\IConfig; + +class Config +{ + public function __construct($appName, IConfig $config) + { + $this->appName = $appName; + $this->config = $config; + } + + public function getAppValue($key, $default = null) + { + $value = $this->config->getAppValue($this->appName, $key, $default); + return (empty($value)) ? $default : $value; + } + + public function setAppValue($key, $value) + { + return $this->config->setAppValue($this->appName, $key, $value); + } + + public function getBooleanAppValue($key) + { + return $this->validateBoolean($this->getAppValue($key)); + } + + private function validateBoolean($val) + { + return $val === true || $val === 'true'; + } +} diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 36745a5..b3474d2 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -2,8 +2,8 @@ namespace OCA\Piwik\Controller; use OCP\AppFramework\Controller; -use OCP\IConfig; use OCP\IRequest; +use OCA\Piwik\Config; class SettingsController extends Controller { @@ -12,7 +12,7 @@ class SettingsController extends Controller public function __construct( $appName, IRequest $request, - IConfig $config + Config $config ) { parent::__construct($appName, $request); @@ -28,10 +28,9 @@ class SettingsController extends Controller return [ 'result' => 'success', 'data' => [ - 'url' => $this->getAppValue('url'), - 'siteId' => $this->getAppValue('siteId'), - 'trackDir' => $this->getBooleanAppValue('trackDir'), - 'validity' => 2*60, + 'url' => $this->config->getAppValue('url'), + 'siteId' => $this->config->getAppValue('siteId'), + 'trackDir' => $this->config->getBooleanAppValue('trackDir') ], ]; } @@ -45,34 +44,13 @@ class SettingsController extends Controller ]; } - $this->setAppValue($key, $this->getTrimParam('value')); + $this->config->setAppValue($key, $this->getTrimParam('value')); return [ 'status' => 'success', ]; } - private function getAppValue($key, $default = null) - { - $value = $this->config->getAppValue($this->appName, $key, $default); - return (empty($value)) ? $default : $value; - } - - private function setAppValue($key, $value) - { - return $this->config->setAppValue($this->appName, $key, $value); - } - - private function getBooleanAppValue($key) - { - return $this->validateBoolean($this->getAppValue($key)); - } - - private function validateBoolean($val) - { - return $val === true || $val === 'true'; - } - private function getTrimParam($key) { return trim($this->request->getParam($key)); |