Skip to content

Commit

Permalink
Remove AppController fc2blog#287
Browse files Browse the repository at this point in the history
- move methods to Web\Controller
  • Loading branch information
uzulla committed Mar 27, 2021
1 parent ca99af2 commit 51edb1b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 75 deletions.
4 changes: 2 additions & 2 deletions app/src/Web/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
64 changes: 0 additions & 64 deletions app/src/Web/Controller/AppController.php

This file was deleted.

51 changes: 51 additions & 0 deletions app/src/Web/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
4 changes: 2 additions & 2 deletions app/src/Web/Controller/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

/**
Expand Down
13 changes: 6 additions & 7 deletions tests/Helper/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +63,7 @@ public function reqBase(
array $postParams = [],
array $getParams = [],
array $filesParams = []
): AppController
): Controller
{
// TODO $_をテストからも可能ならば排除する
$_SESSION = $this->clientTraitSession;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 51edb1b

Please sign in to comment.