mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-10 21:42:17 +00:00
f5a023117a
- Added event-arguments data. - Added event-arguments to the event list in documentation. - Fixed missing exceptions thrown in phpDocs. - Added unit-tests for new event functionality.
62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Pecee\SimpleRouter\Handlers;
|
|
|
|
use Pecee\SimpleRouter\Event\EventArgument;
|
|
use Pecee\SimpleRouter\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;
|
|
}
|
|
|
|
} |