Skip to content

Commit

Permalink
Add convenience method to get the identifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 26, 2024
1 parent 8308710 commit 2a2e337
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Controller/Component/AuthenticationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ public function getResult(): ?ResultInterface
return $this->getAuthenticationService()->getResult();
}

/**
* Get the identifier (primary key) of the identity.
*
* @return array|string|int|null
*/
public function getId(): array|string|int|null
{
return $this->getIdentity()?->getIdentifier();
}

/**
* Returns the identity used in the authentication attempt.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ public function testGetAuthenticationServiceInvalidServiceObject()
$component->getAuthenticationService();
}

public function testGetId(): void
{
$component = new AuthenticationComponent(new ComponentRegistry(new Controller($this->request)));
$this->assertNull($component->getId());

$request = $this->request
->withAttribute('identity', $this->identity)
->withAttribute('authentication', $this->service);

$controller = new Controller($request);
$registry = new ComponentRegistry($controller);
$component = new AuthenticationComponent($registry);

$this->assertSame($component->getId(), $this->identity->getIdentifier());
}

/**
* testGetIdentity
*
Expand Down

0 comments on commit 2a2e337

Please sign in to comment.