Skip to content

Commit 5c4065c

Browse files
committed
User: type fixes in API
1 parent 1d69f82 commit 5c4065c

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/Security/User.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class User
4747
/** @var IUserStorage Session storage for current user */
4848
private $storage;
4949

50-
/** @var IAuthenticator */
50+
/** @var IAuthenticator|null */
5151
private $authenticator;
5252

53-
/** @var IAuthorizator */
53+
/** @var IAuthorizator|null */
5454
private $authorizator;
5555

5656

@@ -73,25 +73,23 @@ final public function getStorage(): IUserStorage
7373

7474
/**
7575
* Conducts the authentication process. Parameters are optional.
76-
* @param mixed optional parameter (e.g. username or IIdentity)
77-
* @param mixed optional parameter (e.g. password)
76+
* @param string|IIdentity username or Identity
7877
* @throws AuthenticationException if authentication was not successful
7978
*/
80-
public function login($id = null, $password = null): void
79+
public function login($user, string $password = null): void
8180
{
8281
$this->logout(true);
83-
if (!$id instanceof IIdentity) {
84-
$id = $this->getAuthenticator()->authenticate(func_get_args());
82+
if (!$user instanceof IIdentity) {
83+
$user = $this->getAuthenticator()->authenticate(func_get_args());
8584
}
86-
$this->storage->setIdentity($id);
85+
$this->storage->setIdentity($user);
8786
$this->storage->setAuthenticated(true);
8887
$this->onLoggedIn($this);
8988
}
9089

9190

9291
/**
9392
* Logs out the user from the current session.
94-
* @param bool clear the identity from persistent storage?
9593
*/
9694
final public function logout(bool $clearIdentity = false): void
9795
{
@@ -158,22 +156,25 @@ final public function getAuthenticator(bool $throw = true): ?IAuthenticator
158156

159157

160158
/**
161-
* Enables log out after inactivity.
162-
* @param string|null like '20 minutes'
163-
* @param int flag IUserStorage::CLEAR_IDENTITY
159+
* Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.
160+
* @param string|null
161+
* @param int
164162
* @return static
165163
*/
166-
public function setExpiration($time, $flags = 0)
164+
public function setExpiration($expire, /*int*/$flags = 0)
167165
{
168166
$clearIdentity = $flags === IUserStorage::CLEAR_IDENTITY;
167+
if ($expire !== null && !is_string($expire)) {
168+
trigger_error("Expiration should be a string like '20 minutes' etc.", E_USER_DEPRECATED);
169+
}
169170
if (is_bool($flags)) {
170171
trigger_error(__METHOD__ . '() second parameter $whenBrowserIsClosed was removed.', E_USER_DEPRECATED);
171172
}
172173
if (func_num_args() > 2) {
173174
$clearIdentity = $clearIdentity || func_get_arg(2);
174175
trigger_error(__METHOD__ . '() third parameter is deprecated, use flag setExpiration($time, IUserStorage::CLEAR_IDENTITY)', E_USER_DEPRECATED);
175176
}
176-
$this->storage->setExpiration($time, $clearIdentity ? IUserStorage::CLEAR_IDENTITY : 0);
177+
$this->storage->setExpiration($expire, $clearIdentity ? IUserStorage::CLEAR_IDENTITY : 0);
177178
return $this;
178179
}
179180

0 commit comments

Comments
 (0)