File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed
Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 2525 "require" : {
2626 "php" : " >=8.1" ,
2727 "cakephp/http" : " ^5.0" ,
28+ "cakephp/utility" : " ^5.0" ,
2829 "laminas/laminas-diactoros" : " ^3.0" ,
2930 "psr/http-client" : " ^1.0" ,
3031 "psr/http-message" : " ^1.1 || ^2.0" ,
Original file line number Diff line number Diff line change 1919use ArrayAccess ;
2020use BadMethodCallException ;
2121use Cake \Core \InstanceConfigTrait ;
22+ use Cake \Utility \Hash ;
2223
2324/**
2425 * Identity object
@@ -102,11 +103,7 @@ public function get(string $field): mixed
102103 $ field = $ map [$ field ];
103104 }
104105
105- if (isset ($ this ->data [$ field ])) {
106- return $ this ->data [$ field ];
107- }
108-
109- return null ;
106+ return Hash::get ($ this ->data , $ field );
110107 }
111108
112109 /**
Original file line number Diff line number Diff line change 1919use ArrayObject ;
2020use Authentication \Identity ;
2121use BadMethodCallException ;
22+ use Cake \ORM \Entity ;
2223use Cake \TestSuite \TestCase ;
2324
2425class IdentityTest extends TestCase
@@ -43,6 +44,22 @@ public function testGetIdentifier()
4344 $ this ->assertSame ('florian ' , $ identity ->username );
4445 }
4546
47+ public function testGet (): void
48+ {
49+ $ data = new Entity ([
50+ 'id ' => 1 ,
51+ 'username ' => 'florian ' ,
52+ 'account ' => new Entity (['id ' => 2 , 'role ' => 'admin ' ]),
53+ ]);
54+
55+ $ identity = new Identity ($ data );
56+
57+ $ this ->assertSame (1 , $ identity ->get ('id ' ));
58+ $ this ->assertSame ('florian ' , $ identity ->get ('username ' ));
59+ $ this ->assertSame ('admin ' , $ identity ->get ('account.role ' ));
60+ $ this ->assertNull ($ identity ->get ('missing ' ));
61+ }
62+
4663 /**
4764 * Test mapping fields
4865 *
You can’t perform that action at this time.
0 commit comments