Skip to content

Commit

Permalink
User: added hasAuthenticator() & hasAuthorizator(), deprecated $throw…
Browse files Browse the repository at this point in the history
… in getAuthenticator() & getAuthorizator()
  • Loading branch information
dg committed Oct 2, 2018
1 parent e53bc8b commit 860a3fb
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,28 @@ public function setAuthenticator(IAuthenticator $handler)
/**
* Returns authentication handler.
*/
final public function getAuthenticator(bool $throw = true): ?IAuthenticator
final public function getAuthenticator(): ?IAuthenticator
{
if ($throw && !$this->authenticator) {
if (func_num_args()) {
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use hasAuthenticator()', E_USER_DEPRECATED);
$throw = func_get_arg(0);
}
if (($throw ?? true) && !$this->authenticator) {
throw new Nette\InvalidStateException('Authenticator has not been set.');
}
return $this->authenticator;
}


/**
* Does the authentication exist?
*/
final public function hasAuthenticator(): bool
{
return (bool) $this->authenticator;
}


/**
* Enables log out after inactivity (like '20 minutes'). Accepts flag IUserStorage::CLEAR_IDENTITY.
* @param string|null $expire
Expand Down Expand Up @@ -244,11 +257,24 @@ public function setAuthorizator(IAuthorizator $handler)
/**
* Returns current authorization handler.
*/
final public function getAuthorizator(bool $throw = true): ?IAuthorizator
final public function getAuthorizator(): ?IAuthorizator
{
if ($throw && !$this->authorizator) {
if (func_num_args()) {
trigger_error(__METHOD__ . '() parameter $throw is deprecated, use hasAuthorizator()', E_USER_DEPRECATED);
$throw = func_get_arg(0);
}
if (($throw ?? true) && !$this->authorizator) {
throw new Nette\InvalidStateException('Authorizator has not been set.');
}
return $this->authorizator;
}


/**
* Does the authorization exist?
*/
final public function hasAuthorizator(): bool
{
return (bool) $this->authorizator;
}
}

0 comments on commit 860a3fb

Please sign in to comment.