From 51edb1b36d45b4981882e315a4afab29417fbb8f Mon Sep 17 00:00:00 2001 From: uzulla Date: Sat, 27 Mar 2021 10:28:24 +0900 Subject: [PATCH] Remove AppController #287 - move methods to Web\Controller --- .../Web/Controller/Admin/AdminController.php | 4 +- app/src/Web/Controller/AppController.php | 64 ------------------- app/src/Web/Controller/Controller.php | 51 +++++++++++++++ .../Web/Controller/User/UserController.php | 4 +- tests/Helper/ClientTrait.php | 13 ++-- 5 files changed, 61 insertions(+), 75 deletions(-) delete mode 100644 app/src/Web/Controller/AppController.php diff --git a/app/src/Web/Controller/Admin/AdminController.php b/app/src/Web/Controller/Admin/AdminController.php index 66e6bf95..21915841 100644 --- a/app/src/Web/Controller/Admin/AdminController.php +++ b/app/src/Web/Controller/Admin/AdminController.php @@ -3,11 +3,11 @@ namespace Fc2blog\Web\Controller\Admin; use Fc2blog\Config; -use Fc2blog\Web\Controller\AppController; +use Fc2blog\Web\Controller\Controller; use Fc2blog\Web\Request; use Fc2blog\Web\Session; -abstract class AdminController extends AppController +abstract class AdminController extends Controller { protected function beforeFilter(Request $request) { diff --git a/app/src/Web/Controller/AppController.php b/app/src/Web/Controller/AppController.php deleted file mode 100644 index 6581dc45..00000000 --- a/app/src/Web/Controller/AppController.php +++ /dev/null @@ -1,64 +0,0 @@ -findById($blog_id); - } - - /** - * デバイスタイプを取得する - * @return string - * @deprecated TODO requestに置換できる - */ - protected function getDeviceType(): string - { - return $this->request->deviceType; - } - - /** - * token発行 - * @param null $key - * @param string $name - * TODO captchaでしかつかっていないので、名前をかえるべき - */ - protected function setToken($key = null, $name = 'token'): void - { - if ($key === null) { - // 適当な値をトークンに設定 - $key = App::genRandomStringAlphaNum(32); - } - Session::set($name, $key); - } - - /** - * tokenチェック - * @param Request $request - * @param string $name - * @return string|null - * TODO captchaでしかつかっていないので、名前をかえるべき - */ - protected function tokenValidate(Request $request, $name = 'token') - { - $value = $request->get($name, ''); - $value = mb_convert_kana($value, 'n'); - return Session::remove($name) == $value ? null : __('Token authentication is invalid'); - } -} diff --git a/app/src/Web/Controller/Controller.php b/app/src/Web/Controller/Controller.php index 9d033783..af1143db 100644 --- a/app/src/Web/Controller/Controller.php +++ b/app/src/Web/Controller/Controller.php @@ -468,4 +468,55 @@ public function getData(): array } return $this->data; } + + /** + * blog_idからブログ情報を取得 + * @param $blog_id + * @return array|false|mixed + * @deprecated TODO Modelに移動するべき + */ + public function getBlog($blog_id) + { + return (new BlogsModel())->findById($blog_id); + } + + /** + * デバイスタイプを取得する + * @return string + * @deprecated TODO requestに置換できる + */ + protected function getDeviceType(): string + { + return $this->request->deviceType; + } + + /** + * token発行 + * @param null $key + * @param string $name + * TODO captchaでしかつかっていないので、名前をかえるべき + */ + protected function setToken($key = null, $name = 'token'): void + { + if ($key === null) { + // 適当な値をトークンに設定 + $key = App::genRandomStringAlphaNum(32); + } + Session::set($name, $key); + } + + /** + * tokenチェック + * @param Request $request + * @param string $name + * @return string|null + * TODO captchaでしかつかっていないので、名前をかえるべき + */ + protected function tokenValidate(Request $request, $name = 'token') + { + $value = $request->get($name, ''); + $value = mb_convert_kana($value, 'n'); + return Session::remove($name) == $value ? null : __('Token authentication is invalid'); + } + } diff --git a/app/src/Web/Controller/User/UserController.php b/app/src/Web/Controller/User/UserController.php index 1ac68b65..51c7cd4f 100644 --- a/app/src/Web/Controller/User/UserController.php +++ b/app/src/Web/Controller/User/UserController.php @@ -3,11 +3,11 @@ namespace Fc2blog\Web\Controller\User; use Fc2blog\Model\BlogsModel; -use Fc2blog\Web\Controller\AppController; +use Fc2blog\Web\Controller\Controller; use Fc2blog\Web\Request; use Fc2blog\Web\Session; -abstract class UserController extends AppController +abstract class UserController extends Controller { /** diff --git a/tests/Helper/ClientTrait.php b/tests/Helper/ClientTrait.php index c3e20d48..ff7f5d5b 100644 --- a/tests/Helper/ClientTrait.php +++ b/tests/Helper/ClientTrait.php @@ -5,8 +5,7 @@ use Fc2blog\Exception\RedirectExit; use Fc2blog\Model\EntriesModel; -use Fc2blog\Web\Controller\AppController; -use Fc2blog\Web\Controller\Controller; + use Fc2blog\Web\Controller\Controller; use Fc2blog\Web\Controller\User\UserController; use Fc2blog\Web\Request; use Fc2blog\Web\Session; @@ -64,7 +63,7 @@ public function reqBase( array $postParams = [], array $getParams = [], array $filesParams = [] - ): AppController + ): Controller { // TODO $_をテストからも可能ならば排除する $_SESSION = $this->clientTraitSession; @@ -161,12 +160,12 @@ public function reqBaseBeRedirect( return $exception; } - public function reqGet(string $path = "/", array $params = []): AppController + public function reqGet(string $path = "/", array $params = []): Controller { return static::reqBase(false, "GET", $path, [], $params); } - public function reqHttpsGet(string $path = "/", array $params = []): AppController + public function reqHttpsGet(string $path = "/", array $params = []): Controller { return static::reqBase(true, "GET", $path, [], $params); } @@ -181,12 +180,12 @@ public function reqHttpsGetBeRedirect(string $path = "/", array $params = []): R return static::reqBaseBeRedirect(true, "GET", $path, [], $params); } - public function reqPost(string $path = "/", array $params = []): AppController + public function reqPost(string $path = "/", array $params = []): Controller { return static::reqBase(false, "POST", $path, $params); } - public function reqHttpsPost(string $path = "/", array $params = []): AppController + public function reqHttpsPost(string $path = "/", array $params = []): Controller { return static::reqBase(true, "POST", $path, $params); }