Skip to content

Commit 577c385

Browse files
committed
removed deprecated IUserStorage (BC break)
1 parent 04073a4 commit 577c385

File tree

8 files changed

+15
-269
lines changed

8 files changed

+15
-269
lines changed

src/Bridges/SecurityDI/SecurityExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ public function loadConfiguration()
8080
$storage->addSetup('setCookieParameters', [$auth->cookieName, $auth->cookieDomain, $auth->cookieSamesite]);
8181
}
8282

83-
$builder->addDefinition($this->prefix('legacyUserStorage')) // deprecated
84-
->setType(Nette\Security\IUserStorage::class)
85-
->setFactory(Nette\Http\UserStorage::class);
86-
8783
$user = $builder->addDefinition($this->prefix('user'))
8884
->setFactory(Nette\Security\User::class);
8985

src/Security/IUserStorage.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Security/User.php

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class User
5454
public array $onLoggedOut = [];
5555

5656
/** Session storage for current user */
57-
private UserStorage|IUserStorage $storage;
57+
private UserStorage $storage;
5858
private ?IAuthenticator $authenticator;
5959
private ?Authorizator $authorizator;
6060
private ?IIdentity $identity = null;
@@ -63,22 +63,17 @@ class User
6363

6464

6565
public function __construct(
66-
?IUserStorage $legacyStorage = null,
66+
UserStorage $storage,
6767
?IAuthenticator $authenticator = null,
6868
?Authorizator $authorizator = null,
69-
?UserStorage $storage = null,
7069
) {
71-
$this->storage = $storage ?? $legacyStorage; // back compatibility
72-
if (!$this->storage) {
73-
throw new Nette\InvalidStateException('UserStorage has not been set.');
74-
}
75-
70+
$this->storage = $storage;
7671
$this->authenticator = $authenticator;
7772
$this->authorizator = $authorizator;
7873
}
7974

8075

81-
final public function getStorage(): UserStorage|IUserStorage
76+
final public function getStorage(): UserStorage
8277
{
8378
return $this->storage;
8479
}
@@ -111,13 +106,8 @@ public function login(
111106
$id = $this->authenticator instanceof IdentityHandler
112107
? $this->authenticator->sleepIdentity($this->identity)
113108
: $this->identity;
114-
if ($this->storage instanceof UserStorage) {
115-
$this->storage->saveAuthentication($id);
116-
} else {
117-
$this->storage->setIdentity($id);
118-
$this->storage->setAuthenticated(true);
119-
}
120109

110+
$this->storage->saveAuthentication($id);
121111
$this->authenticated = true;
122112
$this->logoutReason = null;
123113
Arrays::invoke($this->onLoggedIn, $this);
@@ -130,16 +120,7 @@ public function login(
130120
final public function logout(bool $clearIdentity = false): void
131121
{
132122
$logged = $this->isLoggedIn();
133-
134-
if ($this->storage instanceof UserStorage) {
135-
$this->storage->clearAuthentication($clearIdentity);
136-
} else {
137-
$this->storage->setAuthenticated(false);
138-
if ($clearIdentity) {
139-
$this->storage->setIdentity(null);
140-
}
141-
}
142-
123+
$this->storage->clearAuthentication($clearIdentity);
143124
$this->authenticated = false;
144125
$this->logoutReason = self::LogoutManual;
145126
if ($logged) {
@@ -178,17 +159,11 @@ final public function getIdentity(): ?IIdentity
178159

179160
private function getStoredData(): void
180161
{
181-
if ($this->storage instanceof UserStorage) {
182-
(function (bool $state, ?IIdentity $id, ?int $reason) use (&$identity) {
183-
$identity = $id;
184-
$this->authenticated = $state;
185-
$this->logoutReason = $reason;
186-
})(...$this->storage->getState());
187-
} else {
188-
$identity = $this->storage->getIdentity();
189-
$this->authenticated = $this->storage->isAuthenticated();
190-
$this->logoutReason = $this->storage->getLogoutReason();
191-
}
162+
(function (bool $state, ?IIdentity $id, ?int $reason) use (&$identity) {
163+
$identity = $id;
164+
$this->authenticated = $state;
165+
$this->logoutReason = $reason;
166+
})(...$this->storage->getState());
192167

193168
$this->identity = $identity && $this->authenticator instanceof IdentityHandler
194169
? $this->authenticator->wakeupIdentity($identity)
@@ -255,12 +230,9 @@ final public function hasAuthenticator(): bool
255230
/**
256231
* Enables log out after inactivity (like '20 minutes').
257232
*/
258-
public function setExpiration(?string $expire, bool|int|null $clearIdentity = null)
233+
public function setExpiration(?string $expire, bool $clearIdentity = false)
259234
{
260-
$arg = $this->storage instanceof UserStorage
261-
? (bool) $clearIdentity
262-
: ($clearIdentity ? IUserStorage::CLEAR_IDENTITY : 0);
263-
$this->storage->setExpiration($expire, $arg);
235+
$this->storage->setExpiration($expire, $clearIdentity);
264236
return $this;
265237
}
266238

tests/Security.DI/SecurityExtension.user.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ eval($compiler->compile());
2525
$container = new Container;
2626

2727
Assert::type(Nette\Bridges\SecurityHttp\SessionStorage::class, $container->getService('security.userStorage'));
28-
Assert::type(Nette\Http\UserStorage::class, $container->getService('security.legacyUserStorage'));
2928
Assert::type(Nette\Security\User::class, $container->getService('security.user'));
3029

3130
// aliases

tests/Security/MockUserStorage.legacy.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/Security/User.authentication.legacy.phpt

Lines changed: 0 additions & 117 deletions
This file was deleted.

tests/Security/User.authentication.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Authenticator implements Nette\Security\Authenticator
3636
}
3737

3838

39-
$user = new Nette\Security\User(null, null, null, new MockUserStorage);
39+
$user = new Nette\Security\User(new MockUserStorage);
4040

4141
$counter = (object) [
4242
'login' => 0,

tests/Security/User.authorization.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TesterRole implements Role
5454
}
5555
}
5656

57-
$user = new Nette\Security\User(null, null, null, new MockUserStorage);
57+
$user = new Nette\Security\User(new MockUserStorage);
5858

5959
// guest
6060
Assert::false($user->isLoggedIn());

0 commit comments

Comments
 (0)