Fix docs for themes and theme_admin()

This commit is contained in:
Art4 2024-11-18 22:28:35 +00:00
parent f254283dc6
commit 3c1599323b
3 changed files with 25 additions and 25 deletions

View file

@ -126,14 +126,14 @@ Override the two necessary instances:
```php ```php
use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Capability\ICanWriteToStorage;
abstract class StorageTest abstract class StorageTest
{ {
// returns an instance of your newly created storage class // returns an instance of your newly created storage class
abstract protected function getInstance(); abstract protected function getInstance();
// Assertion for the option array you return for your new StorageClass // Assertion for the option array you return for your new StorageClass
abstract protected function assertOption(ICanWriteToStorage $storage); abstract protected function assertOption(ICanWriteToStorage $storage);
} }
``` ```
## Exception handling ## Exception handling
@ -158,7 +158,7 @@ Example:
```php ```php
use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Capability\ICanWriteToStorage;
class ExampleStorage implements ICanWriteToStorage class ExampleStorage implements ICanWriteToStorage
{ {
public function get(string $reference) : string public function get(string $reference) : string
{ {
@ -168,7 +168,7 @@ class ExampleStorage implements ICanWriteToStorage
throw new \Friendica\Core\Storage\Exception\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);
} }
} }
} }
``` ```
## Example ## Example
@ -200,11 +200,11 @@ class SampleStorageBackend implements ICanWriteToStorage
/** /**
* SampleStorageBackend constructor. * SampleStorageBackend constructor.
* *
* You can add here every dynamic class as dependency you like and add them to a private field * 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 * Friendica automatically creates these classes and passes them as argument to the constructor
*/ */
public function __construct(string $filename) public function __construct(string $filename)
{ {
$this->filename = $filename; $this->filename = $filename;
} }
@ -215,7 +215,7 @@ class SampleStorageBackend implements ICanWriteToStorage
// a config key // a config key
return file_get_contents($this->filename); return file_get_contents($this->filename);
} }
public function put(string $data, string $reference = '') public function put(string $data, string $reference = '')
{ {
if ($reference === '') { if ($reference === '') {
@ -224,13 +224,13 @@ class SampleStorageBackend implements ICanWriteToStorage
// we don't save $data ! // we don't save $data !
return $reference; return $reference;
} }
public function delete(string $reference) public function delete(string $reference)
{ {
// we pretend to delete the data // we pretend to delete the data
return true; return true;
} }
public function __toString() public function __toString()
{ {
return self::NAME; return self::NAME;
@ -261,11 +261,11 @@ class SampleStorageBackendConfig implements ICanConfigureStorage
/** /**
* SampleStorageBackendConfig constructor. * SampleStorageBackendConfig constructor.
* *
* You can add here every dynamic class as dependency you like and add them to a private field * 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 * Friendica automatically creates these classes and passes them as argument to the constructor
*/ */
public function __construct(IManageConfigValues $config, L10n $l10n) public function __construct(IManageConfigValues $config, L10n $l10n)
{ {
$this->config = $config; $this->config = $config;
$this->l10n = $l10n; $this->l10n = $l10n;
@ -289,12 +289,12 @@ class SampleStorageBackendConfig implements ICanConfigureStorage
], ],
]; ];
} }
public function saveOptions(array $data) public function saveOptions(array $data)
{ {
// the keys in $data are the same keys we defined in getOptions() // the keys in $data are the same keys we defined in getOptions()
$newfilename = trim($data['filename']); $newfilename = trim($data['filename']);
// this function should always validate the data. // this function should always validate the data.
// in this example we check if file exists // in this example we check if file exists
if (!file_exists($newfilename)) { if (!file_exists($newfilename)) {
@ -302,9 +302,9 @@ class SampleStorageBackendConfig implements ICanConfigureStorage
// ['optionname' => 'error message'] // ['optionname' => 'error message']
return ['filename' => 'The file doesn\'t exists']; return ['filename' => 'The file doesn\'t exists'];
} }
$this->config->set('storage', 'samplestorage', $newfilename); $this->config->set('storage', 'samplestorage', $newfilename);
// no errors, return empty array // no errors, return empty array
return []; return [];
} }
@ -341,13 +341,13 @@ function samplestorage_storage_uninstall()
DI::storageManager()->unregister(SampleStorageBackend::class); DI::storageManager()->unregister(SampleStorageBackend::class);
} }
function samplestorage_storage_instance(App $a, array &$data) function samplestorage_storage_instance(AppHelper $appHelper, array &$data)
{ {
$config = new SampleStorageBackendConfig(DI::l10n(), DI::config()); $config = new SampleStorageBackendConfig(DI::l10n(), DI::config());
$data['storage'] = new SampleStorageBackendConfig($config->getFileName()); $data['storage'] = new SampleStorageBackendConfig($config->getFileName());
} }
function samplestorage_storage_config(App $a, array &$data) function samplestorage_storage_config(AppHelper $appHelper, array &$data)
{ {
$data['storage_config'] = new SampleStorageBackendConfig(DI::l10n(), DI::config()); $data['storage_config'] = new SampleStorageBackendConfig(DI::l10n(), DI::config());
} }
@ -360,7 +360,7 @@ function samplestorage_storage_config(App $a, array &$data)
use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Capability\ICanWriteToStorage;
use Friendica\Test\src\Core\Storage\StorageTest; use Friendica\Test\src\Core\Storage\StorageTest;
class SampleStorageTest extends StorageTest class SampleStorageTest extends StorageTest
{ {
// returns an instance of your newly created storage class // returns an instance of your newly created storage class
protected function getInstance() protected function getInstance()
@ -382,5 +382,5 @@ class SampleStorageTest extends StorageTest
], ],
], $storage->getOptions()); ], $storage->getOptions());
} }
} }
``` ```

View file

@ -46,9 +46,9 @@ The code will be something like:
// mod/network.php // mod/network.php
<?php <?php
use Friendica\App; use Friendica\AppHelper;
function network_content(App $a) { function network_content(AppHelper $appHelper) {
$itemsmanager = new \Friendica\ItemsManager(); $itemsmanager = new \Friendica\ItemsManager();
$items = $itemsmanager->getAll(); $items = $itemsmanager->getAll();

View file

@ -92,7 +92,7 @@ function theme_admin_post()
} }
} }
function theme_content(App $a): string function theme_content(AppHelper $appHelper): string
{ {
if (!DI::userSession()->getLocalUserId()) { if (!DI::userSession()->getLocalUserId()) {
return ''; return '';
@ -115,7 +115,7 @@ function theme_content(App $a): string
return frio_form($arr); return frio_form($arr);
} }
function theme_admin(): string function theme_admin(AppHelper $appHelper): string
{ {
if (!DI::userSession()->getLocalUserId()) { if (!DI::userSession()->getLocalUserId()) {
return ''; return '';