From 1d4195eb027fa828ebe450ad61114f14e970a054 Mon Sep 17 00:00:00 2001 From: take64 Date: Thu, 20 Jul 2023 22:13:29 +0900 Subject: [PATCH 1/3] =?UTF-8?q?gitignore=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8f1feec..a4af93c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.DS_Store + .idea/ .scannerwork/ src/Library/smarty3/ From f7a07a904f53e000f74b606820ab22549969b779 Mon Sep 17 00:00:00 2001 From: take64 Date: Thu, 20 Jul 2023 22:14:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E5=87=A6=E7=90=86=E3=81=AE=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/ApiController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index dfb72de..18e55d4 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -13,6 +13,7 @@ use Citrus\CitrusException; use Citrus\Http\Server\Request; use Citrus\Http\Server\Response; +use Citrus\Http\Server\ResponseTo; use Citrus\Logger; use Citrus\Message; use Citrus\Message\MessageItem; @@ -46,6 +47,7 @@ public function run(Router|null $router = null): void $request = Request::generate(); $this->initialize($request); + /** @var ResponseTo $response */ $response = $this->$action_name($request); $this->release($request); if (true === Message::exists()) @@ -65,7 +67,7 @@ public function run(Router|null $router = null): void $response_json = json_encode($response); // 出力 - echo $response_json; + echo $response->toJson(); } /** From 72fbd770102ffad12c374bce9c42afa3e364a4f2 Mon Sep 17 00:00:00 2001 From: take64 Date: Thu, 20 Jul 2023 22:15:54 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Authentication.php | 28 ++++++---------------------- src/Controller/ApiController.php | 4 +--- src/Controller/AuthController.php | 3 --- src/Controller/AuthResponse.php | 6 ++---- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/Authentication.php b/src/Authentication.php index dcbdfba..4658e11 100644 --- a/src/Authentication.php +++ b/src/Authentication.php @@ -34,16 +34,16 @@ class Authentication extends Configurable public const SESSION_KEY = 'authentication'; /** @var string 認証テーブル名 */ - public static $AUTHORIZE_TABLE_NAME = 'users'; + public static string $AUTHORIZE_TABLE_NAME = 'users'; /** @var string token生成アルゴリズム */ - public static $TOKEN_ALGO = 'sha256'; + public static string $TOKEN_ALGO = 'sha256'; /** @var int ログイン維持時間(秒) */ - public static $KEEP_SECOND = (60 * 60 * 24); + public static int $KEEP_SECOND = (60 * 60 * 24); - /** @var Protocol 認証タイプインスタンス */ - public $protocol = null; + /** @var Protocol|null 認証タイプインスタンス */ + public Protocol|null $protocol = null; @@ -65,8 +65,6 @@ public function loadConfigures(array $configures = []): Configurable return $this; } - - /** * 認証処理 * @@ -83,8 +81,6 @@ public function authorize(AuthItem $item): bool return $this->protocol->authorize($item); } - - /** * 認証解除処理 * @@ -100,8 +96,6 @@ public function deAuthorize(): bool return $this->protocol->deAuthorize(); } - - /** * 認証のチェック * 認証できていれば期間の延長 @@ -119,8 +113,6 @@ public function isAuthenticated(AuthItem|null $item = null): bool return $this->protocol->isAuthenticated($item); } - - /** * ログイントークンの生成 * @@ -144,14 +136,12 @@ public static function generateToken(string|null $key = null): string ); // tokenキー - $key = ($key ?? Session::$sessionId); + $key ??= Session::$sessionId; // token生成し返却 return hash(self::$TOKEN_ALGO, $key); } - - /** * ログイン維持制限時間の生成 * @@ -162,8 +152,6 @@ public static function generateKeepAt(): string return Dates::now()->addSecond(self::$KEEP_SECOND)->format('Y-m-d H:i:s'); } - - /** * {@inheritDoc} */ @@ -172,8 +160,6 @@ protected function configureKey(): string return 'authentication'; } - - /** * {@inheritDoc} */ @@ -184,8 +170,6 @@ protected function configureDefaults(): array ]; } - - /** * {@inheritDoc} */ diff --git a/src/Controller/ApiController.php b/src/Controller/ApiController.php index 18e55d4..b5dbdbe 100644 --- a/src/Controller/ApiController.php +++ b/src/Controller/ApiController.php @@ -38,7 +38,7 @@ class ApiController extends BaseController public function run(Router|null $router = null): void { // ルーター - $router = ($router ?? Router::sharedInstance()->factory()); + $router ??= Router::sharedInstance()->factory(); $this->router = $router; try @@ -64,8 +64,6 @@ public function run(Router|null $router = null): void Message::removeAll(); } - $response_json = json_encode($response); - // 出力 echo $response->toJson(); } diff --git a/src/Controller/AuthController.php b/src/Controller/AuthController.php index f39ac9f..c5653e0 100644 --- a/src/Controller/AuthController.php +++ b/src/Controller/AuthController.php @@ -50,8 +50,6 @@ public function signin(Request $request): Response return AuthResponse::withToken($item->token); } - - /** * ユーザー情報 * @@ -81,7 +79,6 @@ public function user(Request $request): Response return AuthResponse::withItem($item); } - /** * 認証チェック */ diff --git a/src/Controller/AuthResponse.php b/src/Controller/AuthResponse.php index 6e7c388..116e974 100644 --- a/src/Controller/AuthResponse.php +++ b/src/Controller/AuthResponse.php @@ -22,10 +22,10 @@ class AuthResponse extends Response use Binders; /** @var String 認証用トークン */ - public $token; + public string $token; /** @var array 認証用アイテム */ - public $user; + public array $user; @@ -48,8 +48,6 @@ public static function withToken(string $token): self return $self; } - - /** * user返却用レスポンスの生成 *