6 Commits

Author SHA1 Message Date
as2252258 6a6096ea11 eee 2026-06-12 23:57:22 +08:00
as2252258 b2a89a6f72 eee 2026-01-09 01:10:20 +08:00
as2252258 c08c1731d1 eee 2026-01-09 01:06:50 +08:00
as2252258 846e195efa eee 2025-12-31 00:19:30 +08:00
as2252258 85df6626c1 eee 2025-07-14 15:35:45 +08:00
as2252258 79f430d898 eee 2024-10-09 16:01:22 +08:00
5 changed files with 56 additions and 15 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ class EventDispatch extends Component implements EventDispatcherInterface
try {
call_user_func($item, $event);
} catch (\Throwable $exception) {
error($exception);
\Kiri::getLogger()->json_log($exception);
}
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
break;
+2 -1
View File
@@ -6,8 +6,9 @@ interface EventInterface
{
/**
* @param object $event
* @return void
*/
public function process(): void;
public function process(object $event): void;
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace Kiri\Events;
use Exception;
use Kiri\Di\Interface\InjectTargetInterface;
#[\Attribute]
readonly class EventListener implements InjectTargetInterface
{
/**
* @param string $event
* @throws Exception
*/
public function __construct(public string $event)
{
}
/**
* @param string $class
* @return void
* @throws Exception
*/
public function dispatch(string $class): void
{
// TODO: Implement dispatch() method.
$target = \Kiri::getDi()->getReflectionClass($class)->newInstanceWithoutConstructor();
if (!($target instanceof EventInterface)) {
throw new Exception("Event listen must implement " . EventInterface::class);
}
on($this->event, [$target, "process"]);
}
}
+2 -1
View File
@@ -7,9 +7,10 @@ class TestListener implements EventInterface
/**
* @param object $event
* @return void
*/
public function process(): void
public function process(object $event): void
{
// TODO: Implement process() method.
}
+1 -1
View File
@@ -9,7 +9,7 @@
],
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.5",
"psr/event-dispatcher": "^1.0"
},
"autoload": {