-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrouting.php
More file actions
56 lines (47 loc) · 1.5 KB
/
Copy pathrouting.php
File metadata and controls
56 lines (47 loc) · 1.5 KB
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
<?php
/**
* @codeCoverageIgnoreStart
* phpcs:disable PSR1.Files.SideEffects
* phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Laminas\Diactoros\Response;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
use Lit\Nimo\Handlers\FixedResponseHandler;
use Lit\Voltage\AbstractAction;
use Lit\Voltage\App;
use Lit\Voltage\BasicRouter;
use Lit\Voltage\RouteStubResolver;
use Psr\Http\Message\ResponseInterface;
/** @noinspection PhpIncludeInspection */
require_once __DIR__ . '/../vendor/autoload.php';
class NotFoundAction extends AbstractAction
{
public function __construct()
{
$this->responseFactory = new ResponseFactory();
}
protected function main(): ResponseInterface
{
return $this->json()->render([
'not' => 'found',
'method' => $this->request->getMethod(),
'uri' => $this->request->getUri()->__toString(),
])->withStatus(404);
}
}
$stubResolver = new RouteStubResolver();
$router = new BasicRouter($stubResolver, new NotFoundAction());
$testJson = new Response\JsonResponse([
'test.json' => 'should be this',
'bool' => false,
'nil' => null,
]);
$router->get('/test.json', FixedResponseHandler::wrap($testJson));
$app = new App($router->makeDispatcher());
$request = ServerRequestFactory::fromGlobals();
$response = $app->handle($request);
$emitter = new SapiEmitter();
$emitter->emit($response);
// @codeCoverageIgnoreEnd