Skip to content

Commit ea747cd

Browse files
authored
Merge pull request #540 from kenjis/fix-Config-Auth-class-string
refactor: use `::class` constants
2 parents 579e0a2 + 1d3af81 commit ea747cd

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

docs/auth_actions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Shield ships with two actions you can use, and makes it simple for you to define
1717
Actions are setup in the `Auth` config file, with the `$actions` variable.
1818

1919
```php
20-
public $actions = [
20+
public array $actions = [
2121
'register' => null,
2222
'login' => null,
2323
];
@@ -26,9 +26,9 @@ public $actions = [
2626
To define an action to happen you will specify the class name as the value for the appropriate task:
2727

2828
```php
29-
public $actions = [
30-
'register' => 'CodeIgniter\Shield\Authentication\Actions\EmailActivator',
31-
'login' => 'CodeIgniter\Shield\Authentication\Actions\Email2FA',
29+
public array $actions = [
30+
'register' => \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class,
31+
'login' => \CodeIgniter\Shield\Authentication\Actions\Email2FA::class,
3232
];
3333
```
3434

docs/concepts.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ is provided for you at `CodeIgniter\Shield\Models\UserModel`. You can change thi
2929
The only requirement is that your new class MUST extend the provided `UserModel`.
3030

3131
```php
32-
public $userProvider = 'CodeIgniter\Shield\Models\UserModel';
32+
public string $userProvider = UserModel::class;
3333
```
3434

3535
## User Identities
@@ -80,10 +80,10 @@ You can choose which validators are used in `Config\Auth::$passwordValidators`:
8080

8181
```php
8282
public $passwordValidators = [
83-
'CodeIgniter\Shield\Authentication\Passwords\CompositionValidator',
84-
'CodeIgniter\Shield\Authentication\Passwords\NothingPersonalValidator',
85-
'CodeIgniter\Shield\Authentication\Passwords\DictionaryValidator',
86-
//'CodeIgniter\Shield\Authentication\Passwords\PwnedValidator',
83+
CompositionValidator::class,
84+
NothingPersonalValidator::class,
85+
DictionaryValidator::class,
86+
// PwnedValidator::class,
8787
];
8888
```
8989

docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ By default, once a user registers they have an active account that can be used.
113113

114114
```php
115115
public array $actions = [
116-
'register' => 'CodeIgniter\Shield\Authentication\Actions\EmailActivator',
116+
'register' => \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class,
117117
'login' => null,
118118
];
119119
```
@@ -125,7 +125,7 @@ Turned off by default, Shield's Email-based 2FA can be enabled by specifying the
125125
```php
126126
public array $actions = [
127127
'register' => null,
128-
'login' => 'CodeIgniter\Shield\Authentication\Actions\Email2FA',
128+
'login' => \CodeIgniter\Shield\Authentication\Actions\Email2FA::class,
129129
];
130130
```
131131

src/Config/Auth.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
1010
use CodeIgniter\Shield\Authentication\Authenticators\AccessTokens;
1111
use CodeIgniter\Shield\Authentication\Authenticators\Session;
12+
use CodeIgniter\Shield\Authentication\Passwords\CompositionValidator;
13+
use CodeIgniter\Shield\Authentication\Passwords\DictionaryValidator;
14+
use CodeIgniter\Shield\Authentication\Passwords\NothingPersonalValidator;
15+
use CodeIgniter\Shield\Authentication\Passwords\PwnedValidator;
1216
use CodeIgniter\Shield\Authentication\Passwords\ValidatorInterface;
1317
use CodeIgniter\Shield\Models\UserModel;
1418

@@ -57,8 +61,8 @@ class Auth extends BaseConfig
5761
* You must register actions in the order of the actions to be performed.
5862
*
5963
* Available actions with Shield:
60-
* - register: 'CodeIgniter\Shield\Authentication\Actions\EmailActivator'
61-
* - login: 'CodeIgniter\Shield\Authentication\Actions\Email2FA'
64+
* - register: \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class
65+
* - login: \CodeIgniter\Shield\Authentication\Actions\Email2FA::class
6266
*
6367
* @var array<string, class-string<ActionInterface>|null>
6468
*/
@@ -209,10 +213,10 @@ class Auth extends BaseConfig
209213
* @var class-string<ValidatorInterface>[]
210214
*/
211215
public array $passwordValidators = [
212-
'CodeIgniter\Shield\Authentication\Passwords\CompositionValidator',
213-
'CodeIgniter\Shield\Authentication\Passwords\NothingPersonalValidator',
214-
'CodeIgniter\Shield\Authentication\Passwords\DictionaryValidator',
215-
// 'CodeIgniter\Shield\Authentication\Passwords\PwnedValidator',
216+
CompositionValidator::class,
217+
NothingPersonalValidator::class,
218+
DictionaryValidator::class,
219+
// PwnedValidator::class,
216220
];
217221

218222
/**
@@ -333,7 +337,7 @@ class Auth extends BaseConfig
333337
*
334338
* @var class-string<UserModel>
335339
*/
336-
public string $userProvider = 'CodeIgniter\Shield\Models\UserModel';
340+
public string $userProvider = UserModel::class;
337341

338342
/**
339343
* Returns the URL that a user should be redirected

0 commit comments

Comments
 (0)