diff --git a/doc/Addons.md b/doc/Addons.md index 70b51c3066..7b7e97e701 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -661,7 +661,7 @@ Called when a custom storage is used (e.g. webdav_storage) Hook data: - **name** (input): the name of the used storage backend -- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`) +- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`) ### storage_config @@ -876,7 +876,7 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep- ### src/Content/ContactBlock.php - Hook::callAll('contact_block_end', $arr); + Hook::callAll('contact_block_end', $text); ### src/Content/Text/BBCode.php diff --git a/doc/de/Addons.md b/doc/de/Addons.md index 607f2d50dc..bfc0107528 100644 --- a/doc/de/Addons.md +++ b/doc/de/Addons.md @@ -359,10 +359,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap Hook::callAll('register_account', $uid); Hook::callAll('remove_user', $user); - + ### src/Content/ContactBlock.php - Hook::callAll('contact_block_end', $arr); + Hook::callAll('contact_block_end', $text); ### src/Content/Text/BBCode.php diff --git a/mod/item.php b/mod/item.php index de9a51915a..46f2a219e3 100644 --- a/mod/item.php +++ b/mod/item.php @@ -18,12 +18,12 @@ use Friendica\Content\Conversation; use Friendica\Content\Text\BBCode; -use Friendica\Core\Hook; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Event\ArrayFilterEvent; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\ItemURI; @@ -43,7 +43,11 @@ function item_post() item_drop($uid, $_REQUEST['dropitems']); } - Hook::callAll('post_local_start', $_REQUEST); + $eventDispatcher = DI::eventDispatcher(); + + $_REQUEST = $eventDispatcher->dispatch( + new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_START, $_REQUEST) + )->getArray(); $return_path = $_REQUEST['return'] ?? ''; $preview = intval($_REQUEST['preview'] ?? 0); @@ -275,7 +279,11 @@ function item_process(array $post, array $request, bool $preview, string $return System::jsonExit(['preview' => $o]); } - Hook::callAll('post_local', $post); + $eventDispatcher = DI::eventDispatcher(); + + $post = $eventDispatcher->dispatch( + new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $post) + )->getArray(); unset($post['edit']); unset($post['self']); diff --git a/mod/photos.php b/mod/photos.php index 1294406761..82b5e43960 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -11,12 +11,12 @@ use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; use Friendica\Core\ACL; -use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; +use Friendica\Event\ArrayFilterEvent; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Photo; @@ -647,7 +647,11 @@ function photos_content() 'default_upload' => true ]; - Hook::callAll('photo_upload_form', $ret); + $eventDispatcher = DI::eventDispatcher(); + + $eventDispatcher->dispatch( + new ArrayFilterEvent(ArrayFilterEvent::PHOTO_UPLOAD_FORM, $ret) + ); $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []); $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [ diff --git a/src/App/Router.php b/src/App/Router.php index c5abd56c5c..439b0a743b 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -19,6 +19,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Lock\Capability\ICanLock; use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Event\CollectRoutesEvent; use Friendica\LegacyModule; use Friendica\Module\HTTPException\MethodNotAllowed; use Friendica\Module\HTTPException\PageNotFound; @@ -28,6 +29,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\MethodNotAllowedException; use Friendica\Network\HTTPException\NotFoundException; use Friendica\Util\Router\FriendicaGroupCountBased; +use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Log\LoggerInterface; /** @@ -84,6 +86,8 @@ class Router /** @var LoggerInterface */ private $logger; + private EventDispatcherInterface $eventDispatcher; + private AddonHelper $addonHelper; /** @var bool */ @@ -110,7 +114,7 @@ class Router * @param IHandleUserSessions $userSession * @param RouteCollector|null $routeCollector */ - public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null) + public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, EventDispatcherInterface $eventDispatcher, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null) { $this->baseRoutesFilepath = $baseRoutesFilepath; $this->l10n = $l10n; @@ -120,6 +124,7 @@ class Router $this->config = $config; $this->server = $server; $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; $this->addonHelper = $addonHelper; $this->isLocalUser = !empty($userSession->getLocalUserId()); @@ -148,10 +153,12 @@ class Router $this->addRoutes($routeCollector, $routes); - $this->routeCollector = $routeCollector; - // Add routes from addons - Hook::callAll('route_collection', $this->routeCollector); + $routeCollector = $this->eventDispatcher->dispatch( + new CollectRoutesEvent(CollectRoutesEvent::COLLECT_ROUTES, $routeCollector), + )->getRouteCollector(); + + $this->routeCollector = $routeCollector; return $this; } diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index 1bd891a844..c864f159bb 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -7,10 +7,10 @@ namespace Friendica\Content; -use Friendica\Core\Hook; use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Event\ArrayFilterEvent; use Friendica\Util\Strings; /** @@ -24,8 +24,8 @@ class ContactSelector const SVG_COLOR_WHITE = 2; const SVG_WHITE = 3; - static $serverdata = []; - static $server_id = []; + public static $serverdata = []; + public static $server_id = []; /** * @param string $current current @@ -35,7 +35,7 @@ class ContactSelector public static function pollInterval(string $current, bool $disabled = false): string { $dis = (($disabled) ? ' disabled="disabled" ' : ''); - $o = ''; + $o = ''; $o .= "