[CORE][Event] Make all events return \EventResult, enforced at container build time

This commit is contained in:
2022-04-03 21:40:32 +01:00
parent aef1fac536
commit d4b7e990ce
60 changed files with 345 additions and 239 deletions

View File

@@ -57,6 +57,7 @@ use App\Util\TemporaryFile;
use Component\Attachment\Entity\Attachment;
use Component\Link\Entity\Link;
use Embed\Embed as LibEmbed;
use EventResult;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@@ -111,7 +112,7 @@ class Embed extends Plugin
*
* @throws Exception
*/
public function onAddRoute(Router $m): bool
public function onAddRoute(Router $m): EventResult
{
$m->connect('oembed', 'main/oembed', Controller\OEmbed::class);
return Event::next;
@@ -120,7 +121,7 @@ class Embed extends Plugin
/**
* Insert oembed and opengraph tags in all HTML head elements
*/
public function onShowHeadElements(Request $request, array &$result): bool
public function onShowHeadElements(Request $request, array &$result): EventResult
{
$matches = [];
preg_match(',/?([^/]+)/?(.*),', $request->getPathInfo(), $matches);
@@ -146,7 +147,7 @@ class Embed extends Plugin
/**
* Show this attachment enhanced with the corresponding Embed data, if available
*/
public function onViewLink(array $vars, array &$res): bool
public function onViewLink(array $vars, array &$res): EventResult
{
$link = $vars['link'];
try {
@@ -177,7 +178,7 @@ class Embed extends Plugin
*
* @throws DuplicateFoundException
*/
public function onNewLinkFromNote(Link $link, Note $note): bool
public function onNewLinkFromNote(Link $link, Note $note): EventResult
{
// Only handle text mime
$mimetype = $link->getMimetype();
@@ -368,7 +369,7 @@ class Embed extends Plugin
return HTTPClient::get($url)->getContent();
}
public function onAttachmentGetBestTitle(Attachment $attachment, Note $note, ?string &$title)
public function onAttachmentGetBestTitle(Attachment $attachment, Note $note, ?string &$title): EventResult
{
try {
$embed = DB::findOneBy('attachment_embed', ['attachment_id' => $attachment->getId()]);
@@ -389,7 +390,7 @@ class Embed extends Plugin
*
* @return bool true hook value
*/
public function onPluginVersion(array &$versions): bool
public function onPluginVersion(array &$versions): EventResult
{
$versions[] = [
'name' => 'Embed',