bocharsky-bw / Arrayzy

:package: The wrapper for all PHP built-in array functions and easy, object-oriented array manipulation library. In short: Arrays on steroids.
MIT License
393 stars 38 forks source link

Dot notation? #39

Open undercloud opened 7 years ago

undercloud commented 7 years ago

Support get->('array.get.key') ?

undercloud commented 7 years ago

https://github.com/voku/Arrayy#getstring-key-null-default-null-array--mixed https://github.com/voku/Arrayy#setmixed-key-mixed-value--arrayy-immutable

bocharsky-bw commented 7 years ago

Thanks for this suggestion!

I think (if I understand you right) that you can easily achieve this behavior in your application with the PropertyAccess - a standalone Symfony component. For example:

$array = new Arrayzy([
  'level_0' => [
    'level_1' => [
      'level_2' => 'some-value',
    ],
  ],
]);
$accessor = PropertyAccess::createPropertyAccessor();
$accessor->getValue($array, 'level_0.level_1.level_2')); // return 'some-value'

Does it makes sense for you? I'm not sure we need it out-of-the-box. What do you think? Do you have some good use cases of it?

undercloud commented 7 years ago

I think dot.notation is trend now :smile: For example https://laravel.com/docs/5.3/helpers#method-array-get used in many places id L5

bocharsky-bw commented 7 years ago

OK, let's keep it open for some time, maybe other devs will be interested in it too 😉

AndyDune commented 7 years ago

You can use like this:

$arrayzy = new A(['a' => ['aa' => 'b']]);
$answer = $arrayzy->nested()->get('a.aa'); // b

To check this edit composer.json:

{
    "require": {
        "bocharsky-bw/arrayzy": "dev-master"
    },
    "repositories": [
       {
         "type": "git",
         "url": "https://github.com/AndyDune/Arrayzy"
      }
   ]
}