2020-01-06 17:42:28 +01:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2024-01-02 21:57:26 +01:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-01-06 17:42:28 +01:00
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
2020-01-08 22:51:37 +01:00
|
|
|
use Friendica\Core\Hook;
|
2021-10-23 12:11:38 +02:00
|
|
|
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
2020-01-06 17:42:28 +01:00
|
|
|
|
2020-01-18 20:59:39 +01:00
|
|
|
use Friendica\Core\L10n;
|
2020-01-06 17:42:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A backend storage example class
|
|
|
|
*/
|
2021-10-23 12:11:38 +02:00
|
|
|
class SampleStorageBackend implements ICanWriteToStorage
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
const NAME = 'Sample Storage';
|
|
|
|
|
|
|
|
/** @var L10n */
|
|
|
|
private $l10n;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $options = [
|
|
|
|
'filename' => [
|
|
|
|
'input', // will use a simple text input
|
|
|
|
'The file to return', // the label
|
|
|
|
'sample', // the current value
|
|
|
|
'Enter the path to a file', // the help text
|
|
|
|
// no extra data for 'input' type..
|
|
|
|
],
|
|
|
|
];
|
|
|
|
/** @var array Just save the data in memory */
|
|
|
|
private $data = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SampleStorageBackend constructor.
|
|
|
|
*
|
|
|
|
* @param L10n $l10n 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
|
|
|
|
*/
|
|
|
|
public function __construct(L10n $l10n)
|
|
|
|
{
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:31:57 +02:00
|
|
|
public function get(string $reference): string
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
// we return always the same image data. Which file we load is defined by
|
|
|
|
// a config key
|
2021-08-01 14:31:57 +02:00
|
|
|
return $this->data[$reference] ?? '';
|
2020-01-06 17:42:28 +01:00
|
|
|
}
|
|
|
|
|
2021-08-01 14:31:57 +02:00
|
|
|
public function put(string $data, string $reference = ''): string
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
if ($reference === '') {
|
|
|
|
$reference = 'sample';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->data[$reference] = $data;
|
|
|
|
|
|
|
|
return $reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(string $reference)
|
|
|
|
{
|
|
|
|
if (isset($this->data[$reference])) {
|
|
|
|
unset($this->data[$reference]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:31:57 +02:00
|
|
|
public function getOptions(): array
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
return $this->options;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:31:57 +02:00
|
|
|
public function saveOptions(array $data): array
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
$this->options = $data;
|
|
|
|
|
|
|
|
// no errors, return empty array
|
|
|
|
return $this->options;
|
|
|
|
}
|
|
|
|
|
2021-10-23 12:11:38 +02:00
|
|
|
public function __toString(): string
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:31:57 +02:00
|
|
|
public static function getName(): string
|
2020-01-06 17:42:28 +01:00
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
2020-01-08 22:51:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This one is a hack to register this class to the hook
|
|
|
|
*/
|
|
|
|
public static function registerHook()
|
|
|
|
{
|
|
|
|
Hook::register('storage_instance', __DIR__ . '/SampleStorageBackendInstance.php', 'create_instance');
|
|
|
|
}
|
2020-01-06 17:42:28 +01:00
|
|
|
}
|