Add Router to core.
This commit is contained in:
parent
246bbed148
commit
69c761c3b1
58 changed files with 6451 additions and 157 deletions
62
src/Runtime/Router/Handlers/DebugEventHandler.php
Normal file
62
src/Runtime/Router/Handlers/DebugEventHandler.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Runtime\Router\Handlers;
|
||||
|
||||
use Runtime\Router\Event\EventArgument;
|
||||
use Runtime\Router\Router;
|
||||
|
||||
class DebugEventHandler implements IEventHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Debug callback
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->callback = function (EventArgument $argument) {
|
||||
// todo: log in database
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events.
|
||||
*
|
||||
* @param string|null $name Filter events by name.
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents(?string $name): array
|
||||
{
|
||||
return [
|
||||
$name => [
|
||||
$this->callback,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires any events registered with given event-name
|
||||
*
|
||||
* @param Router $router Router instance
|
||||
* @param string $name Event name
|
||||
* @param array $eventArgs Event arguments
|
||||
*/
|
||||
public function fireEvents(Router $router, string $name, array $eventArgs = []): void
|
||||
{
|
||||
$callback = $this->callback;
|
||||
$callback(new EventArgument($router, $eventArgs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set debug callback
|
||||
*
|
||||
* @param \Closure $event
|
||||
*/
|
||||
public function setCallback(\Closure $event): void
|
||||
{
|
||||
$this->callback = $event;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue