-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHaven.php
More file actions
124 lines (104 loc) · 2.9 KB
/
Haven.php
File metadata and controls
124 lines (104 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
namespace Luxid\Haven;
use Luxid\Contracts\Auth\AuthManager as AuthManagerContract;
use Luxid\Contracts\Auth\Guard as GuardContract;
use Luxid\Contracts\Auth\Authenticatable as AuthenticatableContract;
/**
* Haven static facade.
*
* @package Luxid\Haven
*
* @method static bool attempt(array $credentials, bool $remember = false)
* @method static bool login(AuthenticatableContract $user, bool $remember = false)
* @method static void logout()
* @method static AuthenticatableContract|null user()
* @method static int|string|null id()
* @method static bool check()
* @method static bool guest()
* @method static bool validate(array $credentials)
* @method static GuardContract guard(?string $name = null)
* @method static AuthManagerContract shouldUse(string $name)
* @method static array|null getProvider(?string $name = null)
*/
class Haven implements AuthManagerContract
{
protected static ?AuthManagerContract $manager = null;
/**
* Set the AuthManager instance.
*/
public static function setManager(AuthManagerContract $manager): void
{
self::$manager = $manager;
}
/**
* Get the AuthManager instance.
*/
public static function getManager(): AuthManagerContract
{
if (self::$manager === null) {
throw new \RuntimeException('Haven not initialized.');
}
return self::$manager;
}
/**
* Check if Haven is initialized.
*/
public static function isInitialized(): bool
{
return self::$manager !== null;
}
// AuthManagerContract implementation - delegate to manager
public function guard(?string $name = null): GuardContract
{
return self::getManager()->guard($name);
}
public function shouldUse(string $name): self
{
self::getManager()->shouldUse($name);
return $this;
}
public function user(): ?AuthenticatableContract
{
return self::getManager()->user();
}
public function check(): bool
{
return self::getManager()->check();
}
public function attempt(array $credentials = [], bool $remember = false): bool
{
return self::getManager()->attempt($credentials, $remember);
}
public function login(AuthenticatableContract $user, bool $remember = false): bool
{
return self::getManager()->login($user, $remember);
}
public function logout(): void
{
self::getManager()->logout();
}
public function id()
{
return self::getManager()->id();
}
public function guest(): bool
{
return self::getManager()->guest();
}
public function validate(array $credentials = []): bool
{
return self::getManager()->validate($credentials);
}
public function getProvider(?string $name = null): ?array
{
return self::getManager()->getProvider($name);
}
/**
* Handle dynamic static method calls.
*/
public static function __callStatic(string $method, array $arguments)
{
return self::getManager()->$method(...$arguments);
}
}