Skip to content

Commit 5e6faf3

Browse files
committed
refactor!: add $config property
1 parent 97bda91 commit 5e6faf3

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Auth.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Auth
3333
*/
3434
public const SHIELD_VERSION = '1.0.0-beta.7';
3535

36+
protected AuthConfig $config;
3637
protected ?Authentication $authenticate = null;
3738

3839
/**
@@ -42,16 +43,18 @@ class Auth
4243

4344
protected ?UserModel $userProvider = null;
4445

46+
public function __construct(AuthConfig $config)
47+
{
48+
$this->config = $config;
49+
}
50+
4551
protected function ensureAuthentication(): void
4652
{
4753
if ($this->authenticate !== null) {
4854
return;
4955
}
5056

51-
/** @var AuthConfig $config */
52-
$config = config('Auth');
53-
54-
$authenticate = new Authentication($config);
57+
$authenticate = new Authentication($this->config);
5558
$authenticate->setProvider($this->getProvider());
5659

5760
$this->authenticate = $authenticate;
@@ -150,14 +153,11 @@ public function getProvider(): UserModel
150153
return $this->userProvider;
151154
}
152155

153-
/** @var \CodeIgniter\Shield\Config\Auth $config */
154-
$config = config('Auth');
155-
156-
if (! property_exists($config, 'userProvider')) {
156+
if (! property_exists($this->config, 'userProvider')) {
157157
throw AuthenticationException::forUnknownUserProvider();
158158
}
159159

160-
$className = $config->userProvider;
160+
$className = $this->config->userProvider;
161161
$this->userProvider = new $className();
162162

163163
return $this->userProvider;

src/Config/Services.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use CodeIgniter\Shield\Auth;
99
use CodeIgniter\Shield\Authentication\JWTManager;
1010
use CodeIgniter\Shield\Authentication\Passwords;
11+
use CodeIgniter\Shield\Config\Auth as AuthConfig;
1112

1213
class Services extends BaseService
1314
{
@@ -20,7 +21,10 @@ public static function auth(bool $getShared = true): Auth
2021
return self::getSharedInstance('auth');
2122
}
2223

23-
return new Auth();
24+
/** @var AuthConfig $config */
25+
$config = config('Auth');
26+
27+
return new Auth($config);
2428
}
2529

2630
/**

0 commit comments

Comments
 (0)