- Rename "facStorage" to "storageManager"
- Fix indentation
- Fix tests
This commit is contained in:
nupplaPhil 2020-01-09 01:48:48 +01:00
parent bfae6766bf
commit 016cfcd846
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
7 changed files with 45 additions and 46 deletions

View file

@ -23,7 +23,7 @@ interface IStorage
public function getOptions(); public function getOptions();
public function saveOptions(array $data); public function saveOptions(array $data);
public function __toString(); public function __toString();
public static function getName(); public static function getName();
} }
``` ```
@ -250,13 +250,13 @@ function samplestorage_install()
// on addon install, we register our class with name "Sample Storage". // on addon install, we register our class with name "Sample Storage".
// note: we use `::class` property, which returns full class name as string // note: we use `::class` property, which returns full class name as string
// this save us the problem of correctly escape backslashes in class name // 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() function samplestorage_unistall()
{ {
// when the plugin is uninstalled, we unregister the backend. // 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) function samplestorage_storage_instance(\Friendica\App $a, array $data)

View file

@ -27,7 +27,7 @@ use Psr\Log\LoggerInterface;
* @method static Core\L10n\L10n l10n() * @method static Core\L10n\L10n l10n()
* @method static Core\Process process() * @method static Core\Process process()
* @method static Core\Session\ISession session() * @method static Core\Session\ISession session()
* @method static Core\StorageManager facStorage() * @method static Core\StorageManager storageManager()
* @method static Database\Database dba() * @method static Database\Database dba()
* @method static Factory\Mastodon\Account mstdnAccount() * @method static Factory\Mastodon\Account mstdnAccount()
* @method static Factory\Mastodon\FollowRequest mstdnFollowRequest() * @method static Factory\Mastodon\FollowRequest mstdnFollowRequest()
@ -49,40 +49,40 @@ use Psr\Log\LoggerInterface;
abstract class DI abstract class DI
{ {
const CLASS_MAPPING = [ const CLASS_MAPPING = [
'app' => App::class, 'app' => App::class,
'auth' => App\Authentication::class, 'auth' => App\Authentication::class,
'args' => App\Arguments::class, 'args' => App\Arguments::class,
'baseUrl' => App\BaseURL::class, 'baseUrl' => App\BaseURL::class,
'mode' => App\Mode::class, 'mode' => App\Mode::class,
'module' => App\Module::class, 'module' => App\Module::class,
'page' => App\Page::class, 'page' => App\Page::class,
'router' => App\Router::class, 'router' => App\Router::class,
'contentItem' => Content\Item::class, 'contentItem' => Content\Item::class,
'bbCodeVideo' => Content\Text\BBCode\Video::class, 'bbCodeVideo' => Content\Text\BBCode\Video::class,
'cache' => Core\Cache\ICache::class, 'cache' => Core\Cache\ICache::class,
'config' => Core\Config\IConfiguration::class, 'config' => Core\Config\IConfiguration::class,
'pConfig' => Core\Config\IPConfiguration::class, 'pConfig' => Core\Config\IPConfiguration::class,
'l10n' => Core\L10n\L10n::class, 'l10n' => Core\L10n\L10n::class,
'lock' => Core\Lock\ILock::class, 'lock' => Core\Lock\ILock::class,
'process' => Core\Process::class, 'process' => Core\Process::class,
'session' => Core\Session\ISession::class, 'session' => Core\Session\ISession::class,
'facStorage' => Core\StorageManager::class, 'storageManager' => Core\StorageManager::class,
'dba' => Database\Database::class, 'dba' => Database\Database::class,
'mstdnAccount' => Factory\Mastodon\Account::class, 'mstdnAccount' => Factory\Mastodon\Account::class,
'mstdnFollowRequest' => Factory\Mastodon\FollowRequest::class, 'mstdnFollowRequest' => Factory\Mastodon\FollowRequest::class,
'mstdnRelationship' => Factory\Mastodon\Relationship::class, 'mstdnRelationship' => Factory\Mastodon\Relationship::class,
'cookie' => Model\User\Cookie::class, 'cookie' => Model\User\Cookie::class,
'notify' => Model\Notify::class, 'notify' => Model\Notify::class,
'storage' => Model\Storage\IStorage::class, 'storage' => Model\Storage\IStorage::class,
'intro' => Repository\Introduction::class, 'intro' => Repository\Introduction::class,
'activity' => Protocol\Activity::class, 'activity' => Protocol\Activity::class,
'aclFormatter' => Util\ACLFormatter::class, 'aclFormatter' => Util\ACLFormatter::class,
'dtFormat' => Util\DateTimeFormat::class, 'dtFormat' => Util\DateTimeFormat::class,
'fs' => Util\FileSystem::class, 'fs' => Util\FileSystem::class,
'workerLogger' => Util\Logger\WorkerLogger::class, 'workerLogger' => Util\Logger\WorkerLogger::class,
'profiler' => Util\Profiler::class, 'profiler' => Util\Profiler::class,
'logger' => LoggerInterface::class, 'logger' => LoggerInterface::class,
'devLogger' => '$devLogger', 'devLogger' => '$devLogger',
]; ];
/** @var Dice */ /** @var Dice */

View file

@ -259,7 +259,7 @@ class Attach
$items = self::selectToArray(['backend-class','backend-ref'], $conditions); $items = self::selectToArray(['backend-class','backend-ref'], $conditions);
foreach($items as $item) { foreach($items as $item) {
$backend_class = DI::facStorage()->getByName($item['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
if ($backend_class !== '') { if ($backend_class !== '') {
$fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? ''); $fields['backend-ref'] = $backend_class->put($img->asString(), $item['backend-ref'] ?? '');
} else { } else {
@ -291,7 +291,7 @@ class Attach
$items = self::selectToArray(['backend-class','backend-ref'], $conditions); $items = self::selectToArray(['backend-class','backend-ref'], $conditions);
foreach($items as $item) { foreach($items as $item) {
$backend_class = DI::facStorage()->getByName($item['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($item['backend-class'] ?? '');
if ($backend_class !== null) { if ($backend_class !== null) {
$backend_class->delete($item['backend-ref'] ?? ''); $backend_class->delete($item['backend-ref'] ?? '');
} }

View file

@ -179,7 +179,7 @@ class Photo
} }
$data = $i['data']; $data = $i['data'];
} else { } else {
$backendClass = DI::facStorage()->getByName($photo['backend-class'] ?? ''); $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
$backendRef = $photo['backend-ref'] ?? ''; $backendRef = $photo['backend-ref'] ?? '';
$data = $backendClass->get($backendRef); $data = $backendClass->get($backendRef);
} }
@ -272,7 +272,7 @@ class Photo
if (DBA::isResult($existing_photo)) { if (DBA::isResult($existing_photo)) {
$backend_ref = (string)$existing_photo["backend-ref"]; $backend_ref = (string)$existing_photo["backend-ref"];
$storage = DI::facStorage()->getByName($existing_photo["backend-class"] ?? ''); $storage = DI::storageManager()->getByName($existing_photo["backend-class"] ?? '');
} else { } else {
$storage = DI::storage(); $storage = DI::storage();
} }
@ -336,7 +336,7 @@ class Photo
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions); $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
foreach($photos as $photo) { foreach($photos as $photo) {
$backend_class = DI::facStorage()->getByName($photo['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
if ($backend_class !== null) { if ($backend_class !== null) {
$backend_class->delete($photo["backend-ref"] ?? ''); $backend_class->delete($photo["backend-ref"] ?? '');
} }
@ -365,7 +365,7 @@ class Photo
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions); $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
foreach($photos as $photo) { foreach($photos as $photo) {
$backend_class = DI::facStorage()->getByName($photo['backend-class'] ?? ''); $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
if ($backend_class !== null) { if ($backend_class !== null) {
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']); $fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
} else { } else {

View file

@ -202,7 +202,7 @@ class Site extends BaseAdminModule
$storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
// save storage backend form // save storage backend form
if (DI::facStorage()->setBackend($storagebackend)) { if (DI::storageManager()->setBackend($storagebackend)) {
$storage_opts = DI::storage()->getOptions(); $storage_opts = DI::storage()->getOptions();
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend); $storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
$storage_opts_data = []; $storage_opts_data = [];
@ -534,7 +534,7 @@ class Site extends BaseAdminModule
$available_storage_backends[''] = L10n::t('Database (legacy)'); $available_storage_backends[''] = L10n::t('Database (legacy)');
} }
foreach (DI::facStorage()->listBackends() as $name => $class) { foreach (DI::storageManager()->listBackends() as $name => $class) {
$available_storage_backends[$name] = $name; $available_storage_backends[$name] = $name;
} }

View file

@ -325,7 +325,7 @@ class CronJobs
private static function moveStorage() private static function moveStorage()
{ {
$current = DI::storage(); $current = DI::storage();
$moved = DI::facStorage()->move($current); $moved = DI::storageManager()->move($current);
if ($moved) { if ($moved) {
Worker::add(PRIORITY_LOW, "CronJobs", "move_storage"); Worker::add(PRIORITY_LOW, "CronJobs", "move_storage");

View file

@ -28,7 +28,6 @@ use Friendica\Test\Util\SampleStorageBackend;
* @todo Rework Hook:: methods to dynamic to remove the separated process annotation * @todo Rework Hook:: methods to dynamic to remove the separated process annotation
* *
* @runTestsInSeparateProcesses * @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/ */
class StorageManagerTest extends DatabaseTest class StorageManagerTest extends DatabaseTest
{ {