mirror of
https://github.com/friendica/friendica
synced 2025-04-26 08:30:10 +00:00
Implement Hook::callAll('storage_instance') call for addons and add a description for it.
- Remove implicit Dice usage - Add concrete instance creating - Adding Hook call for addon instance creating - Updating doc for Hook - Updating tests
This commit is contained in:
parent
5d8e6c33ef
commit
bfae6766bf
8 changed files with 155 additions and 62 deletions
|
@ -23,6 +23,7 @@ interface IStorage
|
|||
public function getOptions();
|
||||
public function saveOptions(array $data);
|
||||
public function __toString();
|
||||
public static function getName();
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -85,11 +86,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.
|
||||
|
||||
`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
|
||||
`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
|
||||
|
||||
|
@ -252,6 +258,14 @@ function samplestorage_unistall()
|
|||
// when the plugin is uninstalled, we unregister the backend.
|
||||
DI::facStorage()->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());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Theoretically - until tests for Addons are enabled too - create a test class with the name `addon/tests/SampleStorageTest.php`:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue