Skip to content

Commit

Permalink
[php] define AbstractHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
okashoi committed Nov 3, 2023
1 parent 021ea31 commit bb06472
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 8 deletions.
19 changes: 19 additions & 0 deletions webapp/php/src/AbstractHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace IsuPipe;

use JsonSerializable;
use Psr\Http\Message\ResponseInterface as Response;

abstract class AbstractHandler
{
public function jsonResponse(Response $response, array|JsonSerializable $data, int $status = 200): Response
{
$response->getBody()->write(json_encode($data));

return $response->withHeader('Content-Type', 'application/json')
->withStatus($status);
}
}
2 changes: 1 addition & 1 deletion webapp/php/src/InitializeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* FIXME: ポータルと足並み揃えて修正
*/
class InitializeHandler
class InitializeHandler extends AbstractHandler
{
public function __invoke(Request $request, Response $response): Response
{
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/Livecomment/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\Livecomment;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function getLivecommentsHandler(Request $request, Response $response): Response
{
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/Livestream/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\Livestream;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function reserveLivestreamHandler(Request $request, Response $response): Response
{
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/Payment/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\Payment;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function getPaymentResult(Request $request, Response $response): Response
{
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/Reaction/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\Reaction;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function getReactionsHandler(Request $request, Response $response): Response
{
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/Stats/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\Stats;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function getUserStatisticsHandler(Request $request, Response $response): Response
{
Expand Down
9 changes: 8 additions & 1 deletion webapp/php/src/Top/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

namespace IsuPipe\Top;

use IsuPipe\AbstractHandler;
use PDO;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function __construct(
private PDO $db,
) {
}

public function getTagHandler(Request $request, Response $response): Response
{
// TODO: 実装
Expand Down
3 changes: 2 additions & 1 deletion webapp/php/src/User/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace IsuPipe\User;

use IsuPipe\AbstractHandler;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Handler
class Handler extends AbstractHandler
{
public function getIconHandler(Request $request, Response $response): Response
{
Expand Down

0 comments on commit bb06472

Please sign in to comment.