From 462ff6a942b81bf757a4e9325bf003e9cb1fa8ae Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 30 Jan 2026 11:44:13 +0530 Subject: [PATCH 1/5] Add IdentityHelper::getIdentity() --- src/View/Helper/IdentityHelper.php | 12 ++++++++++++ tests/TestCase/View/Helper/IdentityHelperTest.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/View/Helper/IdentityHelper.php b/src/View/Helper/IdentityHelper.php index 6c2dc947..ca248536 100644 --- a/src/View/Helper/IdentityHelper.php +++ b/src/View/Helper/IdentityHelper.php @@ -120,4 +120,16 @@ 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->_View + ->getRequest() + ->getAttribute($this->getConfig('identityAttribute')); + } } diff --git a/tests/TestCase/View/Helper/IdentityHelperTest.php b/tests/TestCase/View/Helper/IdentityHelperTest.php index b731f769..893418c2 100644 --- a/tests/TestCase/View/Helper/IdentityHelperTest.php +++ b/tests/TestCase/View/Helper/IdentityHelperTest.php @@ -91,4 +91,16 @@ public function testWithOutIdentity() $this->assertFalse($helper->is(1)); } + + 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()); + } } From d3ab4fe081298773479805a71ced2d42a6a9344c Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 30 Jan 2026 13:00:01 +0530 Subject: [PATCH 2/5] Update docblock --- src/View/Helper/IdentityHelper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/View/Helper/IdentityHelper.php b/src/View/Helper/IdentityHelper.php index ca248536..2396afb7 100644 --- a/src/View/Helper/IdentityHelper.php +++ b/src/View/Helper/IdentityHelper.php @@ -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 From 50e6f786ad1af46a933022a51af0f0cd44a9a6f8 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 30 Jan 2026 14:24:05 +0530 Subject: [PATCH 3/5] Use the _identity property Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/View/Helper/IdentityHelper.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/View/Helper/IdentityHelper.php b/src/View/Helper/IdentityHelper.php index 2396afb7..88da0cd7 100644 --- a/src/View/Helper/IdentityHelper.php +++ b/src/View/Helper/IdentityHelper.php @@ -132,8 +132,6 @@ public function get(?string $key = null): mixed */ public function getIdentity(): ?IdentityInterface { - return $this->_View - ->getRequest() - ->getAttribute($this->getConfig('identityAttribute')); + return $this->_identity; } } From cbc12d3717bcc91eef19c64594d97540b9aea51d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 08:54:41 +0000 Subject: [PATCH 4/5] Initial plan From c52efc232eae7831b36a1aafbf7d0fc981288971 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 09:09:51 +0000 Subject: [PATCH 5/5] Add test for getIdentity() returning null without identity Co-authored-by: ADmad <142658+ADmad@users.noreply.github.com> --- tests/TestCase/View/Helper/IdentityHelperTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/TestCase/View/Helper/IdentityHelperTest.php b/tests/TestCase/View/Helper/IdentityHelperTest.php index 893418c2..b41f0162 100644 --- a/tests/TestCase/View/Helper/IdentityHelperTest.php +++ b/tests/TestCase/View/Helper/IdentityHelperTest.php @@ -90,6 +90,8 @@ public function testWithOutIdentity() $this->assertNull($helper->getId()); $this->assertFalse($helper->is(1)); + + $this->assertNull($helper->getIdentity()); } public function testGetIdentity()