Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/View/Helper/IdentityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ public function is(int|string $id, string $field = 'id'): bool
}

/**
* Gets user data
* Get data from the identity.
*
* You can use dot notation to fetch nested data.
* Calling the method without any argument will return
* the entire data array/object (same as `IdentityInterface::getOriginalData()`).
*
* @param string|null $key Key of something you want to get from the identity data
* @return mixed
Expand All @@ -120,4 +124,14 @@ public function get(?string $key = null): mixed

return Hash::get($this->_identity, $key);
}

/**
* Returns the identity instance.
*
* @return \Authentication\IdentityInterface|null
*/
public function getIdentity(): ?IdentityInterface
{
return $this->_identity;
}
}
14 changes: 14 additions & 0 deletions tests/TestCase/View/Helper/IdentityHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,19 @@ public function testWithOutIdentity()
$this->assertNull($helper->getId());

$this->assertFalse($helper->is(1));

$this->assertNull($helper->getIdentity());
}

public function testGetIdentity()
{
$identity = new Identity([
'id' => 1,
]);
$request = (new ServerRequest())->withAttribute('identity', $identity);
$view = new View($request);

$helper = new IdentityHelper($view);
$this->assertSame($identity, $helper->getIdentity());
}
}