-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
45 lines (36 loc) · 1.27 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
<?php
declare(strict_types=1);
session_start();
error_reporting(E_ALL & ~E_NOTICE);
require_once('vendor/autoload.php');
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\ServerRequest;
use GuzzleHttp\Psr7\Response;
use Morgo\Mvc\AppRouter;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
$request = ServerRequest::fromGlobals();
//Create the router dispatcher
$router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $collector) {
$collector->addRoute(['GET','POST'], '/', function ($request, $b) {
_d(get_class($request), get_class($b));
// return $response->getBody()->write('Hello World!');
return 'Hello World!';
});
$routes = require('config/routes.php');
foreach ($routes as $route) {
$collector->addRoute(...$route);
}
});
$queue = [
new Middlewares\FastRoute($router),
new Morgo\Middleware\Test,
new Middlewares\RequestHandler,
function (ServerRequestInterface $request, callable $next) : ResponseInterface {
return new Response(404, [], 'Not Found');
}
];
$dispatcher = Morgo\Factory\MiddlewareDispatcherFactory::create($queue);
$response = $dispatcher->handle($request);
$resolver = new Morgo\App\ResponseResolver;
$resolver->resolve($response);