[Pkg-owncloud-commits] [owncloud-doc] 72/270: chapter on settings

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit 673136d5baaf818e501ebcf5b4c3dac48522618d
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Mon May 12 01:27:31 2014 +0200

    chapter on settings
---
 developer_manual/app/index.rst    |   2 +
 developer_manual/app/settings.rst | 138 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)

diff --git a/developer_manual/app/index.rst b/developer_manual/app/index.rst
index 693db25..7928bcf 100644
--- a/developer_manual/app/index.rst
+++ b/developer_manual/app/index.rst
@@ -27,6 +27,7 @@ App Development
    l10n
    schema
    database
+   settings
    filesystem
    users
    hooks
@@ -88,6 +89,7 @@ Create database tables and run Sql queries:
 
 * :doc:`schema`
 * :doc:`database`
+* :doc:`settings`
 
 
 Filesystem
diff --git a/developer_manual/app/settings.rst b/developer_manual/app/settings.rst
new file mode 100644
index 0000000..1929ebd
--- /dev/null
+++ b/developer_manual/app/settings.rst
@@ -0,0 +1,138 @@
+========
+Settings
+========
+
+.. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
+
+The config allows the app to set global, app and user settings can be injected from the ServerContainer. All values are saved as strings and must be casted to the correct value.
+
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    use \OCP\AppFramework\App;
+
+    use \OCA\MyApp\Service\AuthorService;
+
+
+    class Application extends App {
+
+        public function __construct(array $urlParams=array()){
+            parent::__construct('myapp', $urlParams);
+
+            $container = $this->getContainer();
+
+            /**
+             * Controllers
+             */
+            $container->registerService('AuthorService', function($c) {
+                return new AuthorService(
+                    $c->query('Config'),
+                    $c->query('AppName')
+                );
+            });
+
+            $container->registerService('Config', function($c) {
+                return $c->query('ServerContainer')->getConfig();
+            });
+        }
+    }
+
+System values
+=============
+System values are saved in the :file:`config/config.php` and allow to modify and read the global configuration: 
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    use \OCP\IConfig;
+
+
+    class AuthorService {
+
+        private $config;
+        private $appName;
+
+        public function __construct(IConfig $config, $appName){
+            $this->config = $config;
+            $this->appName = $appName;
+        }
+
+        public function getSystemValue($key) {
+            return $this->config->getSystemValue($key);
+        }
+
+        public function setSystemValue($key, $value) {
+            $this->config->setSystemValue($key, $value);
+        }
+
+    }
+
+
+App values
+==========
+App values are saved in the database per app and are useful for setting global app settings: 
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    use \OCP\IConfig;
+
+
+    class AuthorService {
+
+        private $config;
+        private $appName;
+
+        public function __construct(IConfig $config, $appName){
+            $this->config = $config;
+            $this->appName = $appName;
+        }
+
+        public function getAppValue($key) {
+            return $this->config->getAppValue($this->appName, $key);
+        }
+
+        public function setAppValue($key, $value) {
+            $this->config->setAppValue($this->appName, $key, $value);
+        }
+
+    }
+
+User values
+===========
+User values are saved in the database per user and app and are good for saving user specific app settings: 
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    use \OCP\IConfig;
+
+
+    class AuthorService {
+
+        private $config;
+        private $appName;
+
+        public function __construct(IConfig $config, $appName){
+            $this->config = $config;
+            $this->appName = $appName;
+        }
+
+        public function getSystemValue($key, $userId) {
+            return $this->config->getSystemValue($userId, $this->appName, $key);
+        }
+
+        public function setSystemValue($key, $userId, $value) {
+            $this->config->setSystemValue($userId, $this->appName, $key, $value);
+        }
+
+    }
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list