Skip to content

Commit

Permalink
Merge pull request #6 from kawanamiyuu/fallback-handler
Browse files Browse the repository at this point in the history
add FallbackHandler
  • Loading branch information
kawanamiyuu authored Jul 12, 2020
2 parents 13526f5 + 12a27a3 commit 83d473a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
27 changes: 27 additions & 0 deletions src/FallbackHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace K9u\Framework;

use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class FallbackHandler implements RequestHandlerInterface
{
private ResponseFactoryInterface $responseFactory;

public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
unset($request); // unused

return $this->responseFactory->createResponse(503);
}
}
4 changes: 2 additions & 2 deletions src/FrameworkModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class FrameworkModule extends AbstractModule
* @param array<class-string> $middlewares
* @param AbstractModule|null $module
*/
public function __construct(array $middlewares, AbstractModule $module = null)
public function __construct(array $middlewares = [], AbstractModule $module = null)
{
$this->middlewares = $middlewares;
$this->middlewares = array_merge($middlewares, [FallbackHandler::class]);
parent::__construct($module);
}

Expand Down
6 changes: 1 addition & 5 deletions tests/FrameworkModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ public function setUp(): void

public function testCompile(): void
{
$module = new FrameworkModule([
FakeMiddleware::class,
FakeRequestHandler::class
]);

$module = new FrameworkModule();
$compiler = new DiCompiler($module, __DIR__ . '/../build/tests');
$instance = $compiler->getInstance(ApplicationInterface::class);

Expand Down

0 comments on commit 83d473a

Please sign in to comment.