]> git.mxchange.org Git - friendica.git/blobdiff - doc/AddonStorageBackend.md
Merge remote-tracking branch 'upstream/develop' into personal-copy
[friendica.git] / doc / AddonStorageBackend.md
index 115bfd0035c793477ac2af43d9d71b077264aea3..950a2ad88d9dd6ab26a8f961106c635f61bc41ef 100644 (file)
@@ -23,6 +23,7 @@ interface IStorage
        public function getOptions();
        public function saveOptions(array $data);
        public function __toString();
        public function getOptions();
        public function saveOptions(array $data);
        public function __toString();
+       public static function getName();
 }
 ```
 
 }
 ```
 
@@ -51,7 +52,7 @@ The info array for each option is defined as:
                'type',
 
 define the field used in form, and the type of data.
                'type',
 
 define the field used in form, and the type of data.
-one of 'checkbox', 'combobox', 'custom', 'datetime', 'input', 'intcheckbox', 'password', 'radio', 'richtext', 'select', 'select_raw', 'textarea', 'yesno'
+one of 'checkbox', 'combobox', 'custom', 'datetime', 'input', 'intcheckbox', 'password', 'radio', 'richtext', 'select', 'select_raw', 'textarea'
 
                'label',
 
 
                'label',
 
@@ -72,7 +73,6 @@ Optional. Depends on which 'type' this option is:
 - 'select': array `[ value => label ]` of choices
 - 'intcheckbox': value of input element
 - 'select_raw': prebuild html string of `<option >` tags
 - 'select': array `[ value => label ]` of choices
 - 'intcheckbox': value of input element
 - 'select_raw': prebuild html string of `<option >` tags
-- 'yesno': array `[ 'label no', 'label yes']`
 
 Each label should be translatable
 
 
 Each label should be translatable
 
@@ -85,11 +85,16 @@ See doxygen documentation of `IStorage` interface for details about each method.
 
 Each backend must be registered in the system when the plugin is installed, to be aviable.
 
 
 Each backend must be registered in the system when the plugin is installed, to be aviable.
 
-`DI::facStorage()->register(string $name, string $class)` is used to register the backend class.
-The `$name` must be univocal and will be shown to admin.
+`DI::facStorage()->register(string $class)` is used to register the backend class.
 
 When the plugin is uninstalled, registered backends must be unregistered using
 
 When the plugin is uninstalled, registered backends must be unregistered using
-`DI::facStorage()->unregister(string $name)`.
+`DI::facStorage()->unregister(string $class)`.
+
+You have to register a new hook in your addon, listening on `storage_instance(App $a, array $data)`.
+In case `$data['name']` is your storage class name, you have to instance a new instance of your `Friendica\Model\Storage\IStorage` class.
+Set the instance of your class as `$data['storage']` to pass it back to the backend.
+
+This is necessary because it isn't always clear, if you need further construction arguments.
 
 ## Adding tests
 
 
 ## Adding tests
 
@@ -130,26 +135,26 @@ namespace Friendica\Addon\samplestorage;
 
 use Friendica\Model\Storage\IStorage;
 
 
 use Friendica\Model\Storage\IStorage;
 
-use Friendica\Core\Config;
+use Friendica\Core\Config\IConfig;
 use Friendica\Core\L10n;
 
 class SampleStorageBackend implements IStorage
 {
        const NAME = 'Sample Storage';
 
 use Friendica\Core\L10n;
 
 class SampleStorageBackend implements IStorage
 {
        const NAME = 'Sample Storage';
 
-       /** @var Config\IConfiguration */
+       /** @var IConfig */
        private $config;
        private $config;
-       /** @var L10n\L10n */
+       /** @var L10n */
        private $l10n;
 
        /**
          * SampleStorageBackend constructor.
        private $l10n;
 
        /**
          * SampleStorageBackend constructor.
-         * @param Config\IConfiguration $config The configuration of Friendica
+         * @param IConfig $config The configuration of Friendica
          *                                                                       
          * You can add here every dynamic class as dependency you like and add them to a private field
          * Friendica automatically creates these classes and passes them as argument to the constructor                                                                           
          */
          *                                                                       
          * You can add here every dynamic class as dependency you like and add them to a private field
          * Friendica automatically creates these classes and passes them as argument to the constructor                                                                           
          */
-       public function __construct(Config\IConfiguration $config, L10n\L10n $l10n) 
+       public function __construct(IConfig $config, L10n $l10n) 
        {
                $this->config = $config;
                $this->l10n   = $l10n;
        {
                $this->config = $config;
                $this->l10n   = $l10n;
@@ -244,13 +249,21 @@ function samplestorage_install()
        // on addon install, we register our class with name "Sample Storage".
        // note: we use `::class` property, which returns full class name as string
        // this save us the problem of correctly escape backslashes in class name
        // on addon install, we register our class with name "Sample Storage".
        // note: we use `::class` property, which returns full class name as string
        // this save us the problem of correctly escape backslashes in class name
-       DI::facStorage()->register(SampleStorageBackend::class);
+       DI::storageManager()->register(SampleStorageBackend::class);
 }
 
 function samplestorage_unistall()
 {
        // when the plugin is uninstalled, we unregister the backend.
 }
 
 function samplestorage_unistall()
 {
        // when the plugin is uninstalled, we unregister the backend.
-       DI::facStorage()->unregister(SampleStorageBackend::class);
+       DI::storageManager()->unregister(SampleStorageBackend::class);
+}
+
+function samplestorage_storage_instance(\Friendica\App $a, array $data)
+{
+    if ($data['name'] === SampleStorageBackend::getName()) {
+    // instance a new sample storage instance and pass it back to the core for usage
+        $data['storage'] = new SampleStorageBackend(DI::config(), DI::l10n(), DI::cache());
+    }
 }
 ```
 
 }
 ```