Skip to content

Commit

Permalink
ファイルフォーマットの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
take64 committed Jul 20, 2023
1 parent f7a07a9 commit 72fbd77
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
28 changes: 6 additions & 22 deletions src/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand All @@ -65,8 +65,6 @@ public function loadConfigures(array $configures = []): Configurable
return $this;
}



/**
* 認証処理
*
Expand All @@ -83,8 +81,6 @@ public function authorize(AuthItem $item): bool
return $this->protocol->authorize($item);
}



/**
* 認証解除処理
*
Expand All @@ -100,8 +96,6 @@ public function deAuthorize(): bool
return $this->protocol->deAuthorize();
}



/**
* 認証のチェック
* 認証できていれば期間の延長
Expand All @@ -119,8 +113,6 @@ public function isAuthenticated(AuthItem|null $item = null): bool
return $this->protocol->isAuthenticated($item);
}



/**
* ログイントークンの生成
*
Expand All @@ -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);
}



/**
* ログイン維持制限時間の生成
*
Expand All @@ -162,8 +152,6 @@ public static function generateKeepAt(): string
return Dates::now()->addSecond(self::$KEEP_SECOND)->format('Y-m-d H:i:s');
}



/**
* {@inheritDoc}
*/
Expand All @@ -172,8 +160,6 @@ protected function configureKey(): string
return 'authentication';
}



/**
* {@inheritDoc}
*/
Expand All @@ -184,8 +170,6 @@ protected function configureDefaults(): array
];
}



/**
* {@inheritDoc}
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,8 +64,6 @@ public function run(Router|null $router = null): void
Message::removeAll();
}

$response_json = json_encode($response);

// 出力
echo $response->toJson();
}
Expand Down
3 changes: 0 additions & 3 deletions src/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function signin(Request $request): Response
return AuthResponse::withToken($item->token);
}



/**
* ユーザー情報
*
Expand Down Expand Up @@ -81,7 +79,6 @@ public function user(Request $request): Response
return AuthResponse::withItem($item);
}


/**
* 認証チェック
*/
Expand Down
6 changes: 2 additions & 4 deletions src/Controller/AuthResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class AuthResponse extends Response
use Binders;

/** @var String 認証用トークン */
public $token;
public string $token;

/** @var array 認証用アイテム */
public $user;
public array $user;



Expand All @@ -48,8 +48,6 @@ public static function withToken(string $token): self
return $self;
}



/**
* user返却用レスポンスの生成
*
Expand Down

0 comments on commit 72fbd77

Please sign in to comment.