]> git.mxchange.org Git - friendica.git/blobdiff - doc/AddonStorageBackend.md
Update view/templates/shared_content.tpl
[friendica.git] / doc / AddonStorageBackend.md
index a10d5b00009e6acd71db69b74a23352454cec874..c3a6d1639cb76fb1c587b8c737294038531d990c 100644 (file)
@@ -4,7 +4,7 @@ Friendica Storage Backend Addon development
 * [Home](help)
 
 Storage backends can be added via addons.
-A storage backend is implemented as a class, and the plugin register the class to make it avaiable to the system.
+A storage backend is implemented as a class, and the plugin register the class to make it available to the system.
 
 ## The Storage Backend Class
 
@@ -12,14 +12,14 @@ The class must live in `Friendica\Addon\youraddonname` namespace, where `youradd
 
 There are two different interfaces you need to implement.
 
-### `IWritableStorage`
+### `ICanWriteToStorage`
 
-The class must implement `Friendica\Model\Storage\IWritableStorage` interface. All method in the interface must be implemented:
+The class must implement `Friendica\Core\Storage\Capability\ICanWriteToStorage` interface. All method in the interface must be implemented:
 
 ```php
-namespace Friendica\Model\Storage\IWritableStorage;
+namespace Friendica\Core\Storage\Capability\ICanWriteToStorage;
 
-interface IWritableStorage
+interface ICanWriteToStorage
 {
        public function get(string $reference);
        public function put(string $data, string $reference = '');
@@ -33,17 +33,17 @@ interface IWritableStorage
 - `put(string $data, string $reference)` saves data in `$data` to position `$reference`, or a new position if `$reference` is empty.
 - `delete(string $reference)` delete data pointed by `$reference`
 
-### `IStorageConfiguration`
+### `ICanConfigureStorage`
 
 Each storage backend can have options the admin can set in admin page.
-To make the options possible, you need to implement the `Friendica\Model\Storage\IStorageConfiguration` interface.
+To make the options possible, you need to implement the `Friendica\Core\Storage\Capability\ICanConfigureStorage` interface.
 
 All methods in the interface must be implemented:
 
 ```php
-namespace Friendica\Model\Storage\IStorageConfiguration;
+namespace Friendica\Core\Storage\Capability\ICanConfigureStorage;
 
-interface IStorageConfiguration
+interface ICanConfigureStorage
 {
        public function getOptions();
        public function saveOptions(array $data);
@@ -100,7 +100,7 @@ See doxygen documentation of `IWritableStorage` interface for details about each
 
 ## Register a storage backend class
 
-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 available.
 
 `DI::facStorage()->register(string $class)` is used to register the backend class.
 
@@ -108,7 +108,7 @@ When the plugin is uninstalled, registered backends must be unregistered using
 `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.
+In case `$data['name']` is your storage class name, you have to instance a new instance of your `Friendica\Core\Storage\Capability\ICanReadFromStorage` 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.
@@ -124,7 +124,7 @@ Add a new test class which's naming convention is `StorageClassTest`, which exte
 Override the two necessary instances:
 
 ```php
-use Friendica\Model\Storage\IWritableStorage;
+use Friendica\Core\Storage\Capability\ICanWriteToStorage;
 
 abstract class StorageTest 
 {
@@ -132,7 +132,7 @@ abstract class StorageTest
        abstract protected function getInstance();
 
        // Assertion for the option array you return for your new StorageClass
-       abstract protected function assertOption(IWritableStorage $storage);
+       abstract protected function assertOption(ICanWriteToStorage $storage);
 } 
 ```
 
@@ -140,32 +140,32 @@ abstract class StorageTest
 
 There are two intended types of exceptions for storages
 
-### `ReferenceStorageExecption`
+### `ReferenceStorageException`
 
 This storage exception should be used in case the caller tries to use an invalid references.
 This could happen in case the caller tries to delete or update an unknown reference.
 The implementation of the storage backend must not ignore invalid references.
 
-Avoid throwing the common `StorageExecption` instead of the `ReferenceStorageException` at this particular situation!
+Avoid throwing the common `StorageException` instead of the `ReferenceStorageException` at this particular situation!
 
 ### `StorageException`
 
 This is the common exception in case unexpected errors happen using the storage backend.
-If there's a predecessor to this exception (e.g. you caught an exception and are throwing this execption), you should add the predecessor for transparency reasons.
+If there's a predecessor to this exception (e.g. you caught an exception and are throwing this exception), you should add the predecessor for transparency reasons.
 
 Example:
 
 ```php
-use Friendica\Model\Storage\IWritableStorage;
+use Friendica\Core\Storage\Capability\ICanWriteToStorage;
 
-class ExampleStorage implements IWritableStorage 
+class ExampleStorage implements ICanWriteToStorage 
 {
        public function get(string $reference) : string
        {
                try {
                        throw new Exception('a real bad exception');
                } catch (Exception $exception) {
-                       throw new \Friendica\Model\Storage\StorageException(sprintf('The Example Storage throws an exception for reference %s', $reference), 500, $exception);
+                       throw new \Friendica\Core\Storage\Exception\StorageException(sprintf('The Example Storage throws an exception for reference %s', $reference), 500, $exception);
                }
        }
 } 
@@ -186,12 +186,12 @@ The file will be `addon/samplestorage/SampleStorageBackend.php`:
 <?php
 namespace Friendica\Addon\samplestorage;
 
-use Friendica\Model\Storage\IWritableStorage;
+use Friendica\Core\Storage\Capability\ICanWriteToStorage;
 
-use Friendica\Core\Config\IConfig;
+use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\L10n;
 
-class SampleStorageBackend implements IWritableStorage
+class SampleStorageBackend implements ICanWriteToStorage
 {
        const NAME = 'Sample Storage';
 
@@ -247,14 +247,14 @@ class SampleStorageBackend implements IWritableStorage
 <?php
 namespace Friendica\Addon\samplestorage;
 
-use Friendica\Model\Storage\IStorageConfiguration;
+use Friendica\Core\Storage\Capability\ICanConfigureStorage;
 
-use Friendica\Core\Config\IConfig;
+use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\L10n;
 
-class SampleStorageBackendConfig implements IStorageConfiguration
+class SampleStorageBackendConfig implements ICanConfigureStorage
 {
-       /** @var IConfig */
+       /** @var \Friendica\Core\Config\Capability\IManageConfigValues */
        private $config;
        /** @var L10n */
        private $l10n;
@@ -265,7 +265,7 @@ class SampleStorageBackendConfig implements IStorageConfiguration
          * 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(IConfig $config, L10n $l10n) 
+       public function __construct(IManageConfigValues $config, L10n $l10n) 
        {
                $this->config = $config;
                $this->l10n   = $l10n;
@@ -320,7 +320,7 @@ The file is `addon/samplestorage/samplestorage.php`
 <?php
 /**
  * Name: Sample Storage Addon
- * Description: A sample addon which implements an unusefull storage backend
+ * Description: A sample addon which implements a very limited storage backend
  * Version: 1.0.0
  * Author: Alice <https://alice.social/~alice>
  */
@@ -336,20 +336,20 @@ function samplestorage_install()
        DI::storageManager()->register(SampleStorageBackend::class);
 }
 
-function webdav_storage_uninstall()
+function samplestorage_storage_uninstall()
 {
        DI::storageManager()->unregister(SampleStorageBackend::class);
 }
 
-function webdav_storage_instance(App $a, array &$data)
+function samplestorage_storage_instance(App $a, array &$data)
 {
        $config          = new SampleStorageBackendConfig(DI::l10n(), DI::config());
        $data['storage'] = new SampleStorageBackendConfig($config->getFileName());
 }
 
-function webdav_storage_config(App $a, array &$data)
+function samplestorage_storage_config(App $a, array &$data)
 {
-       $data['storage_config'] = new WebDavConfig(DI::l10n(), DI::config());
+       $data['storage_config'] = new SampleStorageBackendConfig(DI::l10n(), DI::config());
 }
 
 ```
@@ -357,8 +357,8 @@ function webdav_storage_config(App $a, array &$data)
 **Theoretically - until tests for Addons are enabled too - create a test class with the name `addon/tests/SampleStorageTest.php`:
 
 ```php
-use Friendica\Model\Storage\IWritableStorage;
-use Friendica\Test\src\Model\Storage\StorageTest;
+use Friendica\Core\Storage\Capability\ICanWriteToStorage;
+use Friendica\Test\src\Core\Storage\StorageTest;
 
 class SampleStorageTest extends StorageTest 
 {
@@ -371,7 +371,7 @@ class SampleStorageTest extends StorageTest
        }
 
        // Assertion for the option array you return for your new StorageClass
-       protected function assertOption(IWritableStorage $storage)
+       protected function assertOption(ICanWriteToStorage $storage)
        {
                $this->assertEquals([
                        'filename' => [