Skip to content

Commit 9b9d0b7

Browse files
committed
fixes TokenValidatorTrait for CakePHP ^3.6
1 parent eba4f69 commit 9b9d0b7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Form/TokenValidatorTrait.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Cake\ORM\Entity;
88
use Cake\ORM\Locator\LocatorAwareTrait;
99
use Cake\ORM\Table;
10-
use Cake\ORM\TableRegistry;
1110
use Cake\Utility\Hash;
1211
use Cake\Validation\Validator;
1312
use InvalidArgumentException;
@@ -48,7 +47,7 @@ public function __construct($table, $options = [])
4847
*/
4948
public function setTable($table)
5049
{
51-
if (is_subclass_of($table, '\Cake\ORM\Table')) {
50+
if (is_subclass_of($table, \Cake\ORM\Table::class)) {
5251
$this->table = $table;
5352
} else {
5453
$this->table = $this->getTableLocator()->get($table);
@@ -75,7 +74,7 @@ protected function appendTokenValidator(Validator $validator)
7574
{
7675
$tableName = $this->table->getAlias();
7776
$type = $this->settings['type'];
78-
$tokenTable = TableRegistry::get('Elastic/VerifyToken.Tokens');
77+
$tokenTable = $this->getTableLocator()->get('Elastic/VerifyToken.Tokens');
7978

8079
$validator
8180
->notEmptyString('token', __('トークンは必ず入力してください。'))
@@ -100,7 +99,7 @@ protected function appendTokenValidator(Validator $validator)
10099
public function getEntityByToken($token)
101100
{
102101
$tokenTable = $this->getTableLocator()->get('Elastic/VerifyToken.Tokens');
103-
$foreignId = $tokenTable->getForeignIdByToken($token, $this->settings['type'], $this->table->alias());
102+
$foreignId = $tokenTable->getForeignIdByToken($token, $this->settings['type'], $this->table->getAlias());
104103

105104
$user = $this->table->get($foreignId);
106105

@@ -121,7 +120,7 @@ public function getEntityByToken($token)
121120
public function validateToken($token)
122121
{
123122
$tokenTable = $this->getTableLocator()->get('Elastic/VerifyToken.Tokens');
124-
$valid = $tokenTable->validateToken($token, $this->settings['type'], $this->table->alias());
123+
$valid = $tokenTable->validateToken($token, $this->settings['type'], $this->table->getAlias());
125124
if (!$valid) {
126125
throw new InvalidArgumentException(__('無効なトークンです。'));
127126
}

0 commit comments

Comments
 (0)