[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

@@ -36,6 +36,7 @@ declare(strict_types = 1);
namespace App\Core;
use App\Kernel;
use App\Util\Exception\BugFoundException;
use App\Util\Formatting;
use AppendIterator;
use Exception;
@@ -43,6 +44,7 @@ use FilesystemIterator;
use Functional as F;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionMethod;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -85,10 +87,15 @@ class ModuleManager
get_class_methods($obj),
F\ary(F\partial_right('App\Util\Formatting::startsWith', 'on'), 1),
),
function (string $m) use ($obj) {
$ev = mb_substr($m, 2);
$this->events[$ev] ??= [];
$this->events[$ev][] = [$obj, $m];
function (string $method) use ($obj) {
if (((string) (new ReflectionMethod($obj, $method))->getReturnType()) !== 'EventResult') {
$class = $obj::class;
dd("Return type of {$class}::{$method} is not the required EventResult");
throw new BugFoundException("Return type of {$class}::{$method} is not the required EventResult");
}
$event_name = mb_substr($method, 2);
$this->events[$event_name] ??= [];
$this->events[$event_name][] = [$obj, $method];
},
);
}