Skip to content

Commit b3dcf9f

Browse files
committed
IdentityHandler: make getGuestIdentity() a regular interface method (BC break)
Promotes the optional @method to a required method, so User no longer needs method_exists() to call it. BC break: existing IdentityHandler implementations must now declare getGuestIdentity().
1 parent 29ed1fd commit b3dcf9f

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/Security/IdentityHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
/**
1212
* Serializes and restores identity to/from persistent storage.
13-
* @method ?IIdentity getGuestIdentity()
1413
*/
1514
interface IdentityHandler
1615
{
@@ -23,4 +22,9 @@ function sleepIdentity(IIdentity $identity): IIdentity;
2322
* Called after identity is read from storage. Typically refreshes roles or validates the token. Returns null to force logout.
2423
*/
2524
function wakeupIdentity(IIdentity $identity): ?IIdentity;
25+
26+
/**
27+
* Returns the identity for an anonymous (not logged-in) user, or null if none.
28+
*/
29+
function getGuestIdentity(): ?IIdentity;
2630
}

src/Security/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private function resolveGuestIdentity(): ?IIdentity
178178
{
179179
if (!$this->guestIdentityResolved) {
180180
$this->guestIdentityResolved = true;
181-
$this->guestIdentity = $this->authenticator instanceof IdentityHandler && method_exists($this->authenticator, 'getGuestIdentity')
181+
$this->guestIdentity = $this->authenticator instanceof IdentityHandler
182182
? $this->authenticator->getGuestIdentity()
183183
: null;
184184
}

0 commit comments

Comments
 (0)