-
Notifications
You must be signed in to change notification settings - Fork 5
/
benchmark.php
37 lines (31 loc) · 1.02 KB
/
benchmark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require 'vendor/autoload.php';
use Brick\App\Application;
use Brick\Http\Request;
use Brick\Http\Response;
use Brick\App\Routing\Route;
use Brick\App\Routing\RouteMatch;
use Brick\App\Event\NonResponseResultEvent;
class MyRoute implements Route{
public function match(Request $request) {
return RouteMatch::forFunction(function() {
return ["test" => "hop"];
});
}
}
class JsonPlugin implements \Brick\App\Plugin
{
public function register(\Brick\Event\EventDispatcher $dispatcher)
{
$dispatcher->addListener(NonResponseResultEvent::class, function (NonResponseResultEvent $event) {
$response = new Response();
$response->setContent(json_encode($event->getControllerResult()));
$response->setHeader('Content-Type', 'application/json');
$event->setResponse($response);
});
}
}
$application = Application::create();
$application->addRoute(new MyRoute());
$application->addPlugin(new JsonPlugin());
$application->run();