Remove App dependency from Hook::callSingle

- This was causing a circular dependency with the logger_instance hook
This commit is contained in:
Hypolite Petovan 2023-01-13 21:10:59 -05:00
commit e73adde5fb
8 changed files with 37 additions and 67 deletions

View file

@ -167,7 +167,7 @@ class Hook
if ($hook[0] != $fork_hook[0]) {
continue;
}
self::callSingle(DI::app(), 'hook_fork', $fork_hook, $hookdata);
self::callSingle('hook_fork', $fork_hook, $hookdata);
}
if (!$hookdata['execute']) {
@ -195,7 +195,7 @@ class Hook
{
if (array_key_exists($name, self::$hooks)) {
foreach (self::$hooks[$name] as $hook) {
self::callSingle(DI::app(), $name, $hook, $data);
self::callSingle($name, $hook, $data);
}
}
}
@ -203,24 +203,23 @@ class Hook
/**
* Calls a single hook.
*
* @param App $a
* @param string $name of the hook to call
* @param array $hook Hook data
* @param string|array &$data to transmit to the callback handler
* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function callSingle(App $a, string $name, array $hook, &$data = null)
public static function callSingle(string $name, array $hook, &$data = null)
{
// Don't run a theme's hook if the user isn't using the theme
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . DI::app()->getCurrentTheme()) === false) {
return;
}
@include_once($hook[0]);
if (function_exists($hook[1])) {
$func = $hook[1];
$func($a, $data);
$func($data);
} else {
// remove orphan hooks
$condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];

View file

@ -36,15 +36,12 @@ class Addons extends BaseSettings
{
/** @var Database */
private $database;
/** @var App */
private $app;
public function __construct(App $app, Database $database, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(Database $database, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->database = $database;
$this->app = $app;
}
protected function post(array $request = [])
@ -62,7 +59,7 @@ class Addons extends BaseSettings
$addon_settings_forms = [];
foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) {
$data = [];
Hook::callSingle($this->app, 'addon_settings', [$hook['file'], $hook['function']], $data);
Hook::callSingle('addon_settings', [$hook['file'], $hook['function']], $data);
if (!empty($data['href'])) {
$tpl = Renderer::getMarkupTemplate('settings/addons/link.tpl');

View file

@ -49,10 +49,8 @@ class Connectors extends BaseSettings
private $database;
/** @var SystemMessages */
private $systemMessages;
/** @var App */
private $app;
public function __construct(App $app, SystemMessages $systemMessages, Database $database, IManagePersonalConfigValues $pconfig, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(SystemMessages $systemMessages, Database $database, IManagePersonalConfigValues $pconfig, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
@ -60,7 +58,6 @@ class Connectors extends BaseSettings
$this->pconfig = $pconfig;
$this->database = $database;
$this->systemMessages = $systemMessages;
$this->app = $app;
}
protected function post(array $request = [])
@ -146,7 +143,7 @@ class Connectors extends BaseSettings
$connector_settings_forms = [];
foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'connector_settings']) as $hook) {
$data = [];
Hook::callSingle($this->app, 'connector_settings', [$hook['file'], $hook['function']], $data);
Hook::callSingle('connector_settings', [$hook['file'], $hook['function']], $data);
$tpl = Renderer::getMarkupTemplate('settings/addons/connector.tpl');
$connector_settings_forms[$data['connector']] = Renderer::replaceMacros($tpl, [
@ -160,7 +157,7 @@ class Connectors extends BaseSettings
]);
}
if ($this->app->isSiteAdmin()) {
if ($this->session->isSiteAdmin()) {
$diasp_enabled = $this->config->get('system', 'diaspora_enabled') ?
$this->t('Built-in support for %s connectivity is enabled', $this->t('Diaspora (Socialhome, Hubzilla)')) :
$this->t('Built-in support for %s connectivity is disabled', $this->t('Diaspora (Socialhome, Hubzilla)'));

View file

@ -51,7 +51,7 @@ class Expire
foreach (Hook::getByName('expire') as $hook) {
if ($hook[1] == $hook_function) {
Logger::info('Calling expire hook', ['hook' => $hook[1]]);
Hook::callSingle($a, 'expire', $hook, $data);
Hook::callSingle('expire', $hook, $data);
}
}
return;

View file

@ -28,8 +28,6 @@ Class ForkHook
{
public static function execute($name, $hook, $data)
{
$a = DI::app();
Hook::callSingle($a, $name, $hook, $data);
Hook::callSingle($name, $hook, $data);
}
}