-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
60 lines (54 loc) · 1.89 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types = 1);
require '../vendor/autoload.php';
$injector = (function ($i) {
$i->define(
Middlewares\Fastroute::class,
[':router' => FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
require '../config/routes.php';
})]
);
require '../config/injector.php';
return $i;
})(new Auryn\Injector());
$middlewares = require '../config/middlewares.php';
$middlewares[] = function (Psr\Http\Message\ServerRequestInterface $request) use ($injector) {
$handler = $request->getAttribute('request-handler');
if (is_string($handler) && class_exists($handler)) {
$handler = $injector->make($handler);
}
if ($handler instanceof Psr\Http\Server\RequestHandlerInterface) {
return $handler->handle($request);
}
throw new RuntimeException(sprintf('Invalid request handler: %s', gettype($handler)));
};
$request = $injector->make(Nyholm\Psr7Server\ServerRequestCreator::class);
(new Zend\HttpHandlerRunner\Emitter\SapiEmitter)
->emit(
(new Middleland\Dispatcher(
$middlewares,
new class($injector) implements Psr\Container\ContainerInterface {
private $injector;
public function __construct($injector)
{
$this->injector = $injector;
}
public function get($id)
{
return $this->injector->make($id);
}
public function has($id)
{
return true;
}
}
))->dispatch($request->fromArrays(
$_SERVER,
function_exists('getallheaders') ? getallheaders() : $request->getHeadersFromServer($_SERVER),
$_COOKIE,
$_GET,
$_POST,
$_FILES,
fopen('php://input', 'r')
))
);