Object search support for ake() #236

Closed
opened 2021-04-22 02:45:07 +00:00 by jamie · 5 comments
jamie commented 2021-04-22 02:45:07 +00:00 (Migrated from git.hazaar.io)

So my Hazaar\Model\Strict class has dot-notation search support in it's ::get() method. I'm going to copy a lot of that and add the same feature to ake().

This will mean that ake() dot-notation references will be able to do this:

$value = ake($object, 'names(nameType.id=1).content');

This will look at the names element of $object and search each of it's elements for nameType.id that equals 1 and then from that return the content element.

This is probably the shorted issue detail for probably one of the largest and most impactful changes I have ever made. ake() is my most favourite function and has not been updated in years. I'm excited to add this new feature to it without impacting existing functionality.

So my `Hazaar\Model\Strict` class has dot-notation search support in it's `::get()` method. I'm going to copy a lot of that and add the same feature to `ake()`. This will mean that `ake()` dot-notation references will be able to do this: ```php $value = ake($object, 'names(nameType.id=1).content'); ``` This will look at the `names` element of `$object` and search each of it's elements for `nameType.id` that equals `1` and then from that return the `content` element. This is probably the shorted issue detail for probably one of the largest and most impactful changes I have ever made. `ake()` is my most favourite function and has not been updated in years. I'm excited to add this new feature to it without impacting existing functionality.
jamie commented 2021-04-22 02:53:46 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2021-04-22 02:53:49 +00:00 (Migrated from git.hazaar.io)

created merge request !130 to address this issue

created merge request !130 to address this issue
jamie commented 2021-04-22 02:53:49 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !130

mentioned in merge request !130
jamie commented 2021-04-22 03:14:25 +00:00 (Migrated from git.hazaar.io)

My example code for development:

$data = [
  'name' => 'Jamie Carl',
  'dob' => '13/12/1978',
  'status' => 'Married',
  'emails' => [
    ['type' => 1, 'content' =>'test1@hazaar.io'],
    ['type' => 1, 'content' =>'test2@hazaar.io'],
    ['type' => 2, 'content' => 'test3@hazaar.io']
  ]
];

dump(ake($data, 'emails(type=2).content'));

This should end up returning test3@hazaar.io.

My example code for development: ```php $data = [ 'name' => 'Jamie Carl', 'dob' => '13/12/1978', 'status' => 'Married', 'emails' => [ ['type' => 1, 'content' =>'test1@hazaar.io'], ['type' => 1, 'content' =>'test2@hazaar.io'], ['type' => 2, 'content' => 'test3@hazaar.io'] ] ]; dump(ake($data, 'emails(type=2).content')); ``` This should end up returning `test3@hazaar.io`.
jamie commented 2021-04-22 04:13:36 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 216d233eafc8b2149bc0753a05f4359fa0f49b02

mentioned in commit 216d233eafc8b2149bc0753a05f4359fa0f49b02
jamie (Migrated from git.hazaar.io) closed this issue 2021-04-22 04:13:36 +00:00
jamie self-assigned this 2025-09-04 01:15:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#236
No description provided.