mirror of
https://github.com/friendica/friendica
synced 2025-02-14 15:34:11 +00:00
Replace Hook with EventDispatcher in Feature class
This commit is contained in:
parent
b9a191f6d8
commit
f3ccd198a4
4 changed files with 21 additions and 5 deletions
|
@ -9,6 +9,7 @@ namespace Friendica\Content;
|
|||
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\DI;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
|
||||
class Feature
|
||||
{
|
||||
|
@ -41,15 +42,23 @@ class Feature
|
|||
*/
|
||||
public static function isEnabled(int $uid, $feature): bool
|
||||
{
|
||||
if (!DI::config()->get('feature_lock', $feature, false)) {
|
||||
$enabled = DI::config()->get('feature', $feature) ?? self::getDefault($feature);
|
||||
$enabled = DI::pConfig()->get($uid, 'feature', $feature) ?? $enabled;
|
||||
$config = DI::config();
|
||||
$pConfig = DI::pConfig();
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
if (!$config->get('feature_lock', $feature, false)) {
|
||||
$enabled = $config->get('feature', $feature) ?? self::getDefault($feature);
|
||||
$enabled = $pConfig->get($uid, 'feature', $feature) ?? $enabled;
|
||||
} else {
|
||||
$enabled = true;
|
||||
}
|
||||
|
||||
$arr = ['uid' => $uid, 'feature' => $feature, 'enabled' => $enabled];
|
||||
Hook::callAll('isEnabled', $arr);
|
||||
|
||||
$arr = $eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::FEATURE_ENABLED, $arr)
|
||||
)->getArray();
|
||||
|
||||
return (bool)$arr['enabled'];
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ final class ArrayFilterEvent extends Event
|
|||
|
||||
public const NAV_INFO = 'friendica.data.nav_info';
|
||||
|
||||
public const FEATURE_ENABLED = 'friendica.data.feature_enabled';
|
||||
|
||||
private array $array;
|
||||
|
||||
public function __construct(string $name, array $array)
|
||||
|
|
|
@ -38,6 +38,7 @@ final class HookEventBridge
|
|||
ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
|
||||
ArrayFilterEvent::APP_MENU => 'app_menu',
|
||||
ArrayFilterEvent::NAV_INFO => 'nav_info',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
|
||||
HtmlFilterEvent::HEAD => 'head',
|
||||
HtmlFilterEvent::FOOTER => 'footer',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
||||
|
@ -55,6 +56,7 @@ final class HookEventBridge
|
|||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||
|
@ -88,7 +90,7 @@ final class HookEventBridge
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string|array $data
|
||||
* @param string|array|object $data
|
||||
*
|
||||
* @return string|array|object
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,7 @@ class HookEventBridgeTest extends TestCase
|
|||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||
|
@ -114,6 +115,8 @@ class HookEventBridgeTest extends TestCase
|
|||
return [
|
||||
['test', 'test'],
|
||||
[ArrayFilterEvent::APP_MENU, 'app_menu'],
|
||||
[ArrayFilterEvent::NAV_INFO, 'nav_info'],
|
||||
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue