Verze: 0.3
- 0.6 (master)
- 0.5
- 0.4
- 0.3
- 0.2
Event manager
Vykreslení výstupu Response() má event Router::RESPONSE_RENDER_EVENT.
V hlavním souboru se zaregistruje listener:
index.php
<?php
use Gephart\DependencyInjection\Container;
use Gephart\Configuration\Configuration;
use Gephart\Routing\Router;
include_once __DIR__ . "/vendor/autoload.php";
$container = new Container();
$configuration = $container->get(Configuration::class);
$configuration->setDirectory(__DIR__ . "/config");
$container->get(\App\EventListener\ResponseListener::class);
$router = $container->get(Router::class);
$router->run();
src/App/EventListener/ResponseListener.php
<?php
namespace App\EventListener;
use Gephart\EventManager\Event;
use Gephart\EventManager\EventManager;
use Gephart\Routing\Router;
class ResponseListener
{
public function __construct(EventManager $event_manager)
{
$event_manager->attach(Router::RESPONSE_RENDER_EVENT, [$this, "responseRender"]);
}
public function responseRender(Event $event)
{
$response = $event->getParam("response");
$response .= "Hello by listener";
$event->setParams([
"response" => $response
]);
}
}