Giter VIP home page Giter VIP logo

php-dot-notation's People

Contributors

adbario avatar gmsantos avatar localheinz avatar melbings avatar nicoorfi avatar peter279k avatar qaharmdz avatar szepeviktor avatar vanodevium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-dot-notation's Issues

Configurable Separator

I'm wondering if you'd be open to a configurable separator. I'd offer a pull request on 2.X non-BC breaking, which is what we're currently using, for a 2.5 version. While we don't have a preference I could see this working two different ways or both:

Idea # 1:

Given I can flatten('_') it seems I should also be able to do something like set($key, $value, '_') ... adding an optional $separator parameter to effectively any method interface that allows you to do notation parsing.

Idea # 2:

At least creating an internal $separator property, and having a general setSeparator() property which would allow for changing it and/or temporarily changing it and changing it back as needed.

Idea # 3:

A combination of both where instead of setSeparator() it's setDefaultSeparator() and you're still able to overload on a per method call basis.

If this is something you're open to, let me know and I'll get in a pull request. Again, our concern is on the 2.X version, but if you want to make the equivalent change on 3.X it should be pretty easy based on the pull request.

Deprecation Notice? Adbar\Dot should either be compatible with ArrayAccess

Deprecation Notice: Return type of Adbar\Dot::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:510
Deprecation Notice: Return type of Adbar\Dot::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:521
Deprecation Notice: Return type of Adbar\Dot::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:532
Deprecation Notice: Return type of Adbar\Dot::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:548
Deprecation Notice: Return type of Adbar\Dot::count($key = null) should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:565
Deprecation Notice: Return type of Adbar\Dot::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:581
Deprecation Notice: Return type of Adbar\Dot::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/luke.english/sftp/instance/vendor/adbario/php-dot-notation/src/Dot.php:597

Indirect modification of overloaded element of Adbar\Dot has no effect

use Adbar\Dot;

$CONFIG = new Dot();

...
$CONFIG['SPHINX']['articles_search_weights'] = [       // line 194:
    'title'     => 50,
    'short'     => 30,
    'text'      => 20,
    'author'    => 5
];

Result:

PHP Notice:  Indirect modification of overloaded element of Adbar\Dot has no effect in foobar.php  on line 194

Replace (more specifically replace recursive)

I notice there's a merge() function, which of course is quite useful, although it doesn't look like it does so recursively. I'm wondering if there would be any support for adding a replace() function using PHP's array_replace() similarly.

Lastly, and most useful, I believe, mergeRecursive() and replaceRecursive().

Deprecated error with php8

Error Message:
PHP Deprecated: Return type of Adbar\Dot::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/dyn/AliGitRepo/openapi-sdk-php-client/vendor/adbario/php-dot-notation/src/Dot.php on line 603

"adbario/php-dot-notation": "^2.3"

Parsing empty array all() returns null

When parsing an empty array items, calling all() return null, but I would expect an empty array.

$dot = new Dot([], true);
$dot->all(); // this returns null

Question: Wildcards

Hi,
Is it possible to use wildcards?
Sth. like this: "array.value.*.array.value"

Thank you

Add ability to parse arrays containing objects

Considering the following array:

$arr = array(
        'foo' => array(
            'bar' => 'inner value'
        ),
        'fooObj' => (object) array(
            'objAttribute' => 'some value'
        ),
);

$dot = new \Adbar\Dot($arr);

var_dump($dot->has('foo.bar')); // bool(true)
var_dump($dot->has('fooObj.objAttribute')); // bool(false)

Would it be possible to extend Dot to also include objects (nested or not nested inside arrays).

array unflatten

It would be nice to be able to unflatten a dot notated array.

Set/merge methods does not split key with dot

$dot->set('A', [
    'E.X'   =>  5,
    'E.Y'   =>  6,
    'F'     =>  7
]);
var_dump( $dot->get() );

Return:

array(1) {
  ["A"]=>
  array(3) {
    ["E.X"]=>
    int(5)
    ["E.Y"]=>
    int(6)
    ["F"]=>
    int(7)
  }
}

Expected:

array(1) {
  ["A"]=> array(2) {
    ["E"]=> array(2) {
       ["X"] => int(5)
       ["Y"] => int(6)
    }
    ["F"] =>   int(7)
  }
}

Add __set_state() for var_export() support

Using var export to export executable PHP into a cache file is good for performance, especially if the collection is being packed with lots of data from lots of config files. I'd like to be able to export the whole collection and restore... should be as simple as:

static public function __set_state($data)
{
    return new static($data['items']);
}

How to access element of array

Assuming you are loading from the ./composer.json file, how would one get the first element of the array

$value = $config->get('authors[0].name');
$value = $config->get('authors.0.name');

If i were accessing as an array,

$value = $array["authors"][0]["name"];

php 8.1 deprecations

Hey, on 8.1 I get a few deprecations like

Deprecated: Return type of Adbar\Dot::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

  • ArrayAccess::offsetExists(mixed $offset): bool
  • ArrayAccess::offsetGet(mixed $offset): mixed
  • ArrayAccess::offsetSet(mixed $offset, mixed $value): void
  • ArrayAccess::offsetUnset(mixed $offset): void
  • Countable::count(): int
  • IteratorAggregate::getIterator(): Traversable
  • JsonSerializable::jsonSerialize(): mixed

can we add the ReturnTypeWillChange attribute?

Set method does not split key with dot

$dot = new \Adbar\Dot();

$dot->set('LOGGING.KEY_3', 3);

$dot->set('LOGGING', [
    'KEY_1'       =>  1,
    'KEY_2'             =>  2,
]);

var_dump( $dot->get('LOGGING.KEY_3') );

var_dump( $dot->get('LOGGING') );

var_dump( $dot->get() );

Return:

NULL
array(2) {
  ["KEY_1"]=>
  int(1)
  ["KEY_2"]=>
  int(2)
}
array(1) {
  ["LOGGING"]=>
  array(2) {
    ["KEY_1"]=>
    int(1)
    ["KEY_2"]=>
    int(2)
  }
}

Expected not null and array with KEY_3 => (int)3

Cannot access key

I have a file that I'm reading that is like:

key1.status=value1
key1.a=value2
key1.a.b=value3

I'm having issues trying to access key1.a ... it keeps giving me an array to string error, and cannot see how to access it. Also, when I dump toJson, key1.a is not in the JSON. Not sure if that's related.

Add ability to filter results by value e.g $comedies = $dot->get('movies[genre=comedy]');

Hey wasn't too sure where to put this so creating an issue. Was thinking of updating the class to be able to do queries like below. Just wanna know if this would get merged. If anyone needs this.

$array = [
    'key1' => 'value1',
    'key2' => 'value2',
    'movies' => [
        [
            'id'    => 1,
            'title' => 'Dumb And Dumber',
            'genre' => 'comedy'
        ],
        [
            'id'    => 2,
            'title' => 'The Mask',
            'genre' => 'comedy'
        ],
        [
            'id'    => 3,
            'title' => 'Eternal Sunshine of the Spotless Mind',
            'genre' => 'drama'
        ],
    ]
];

$comedies = $dot->get('movies[genre=comedy]');

// Commedy would be at the end
$comedies = [
    [
        'id'    => 1,
        'title' => 'Dumb And Dumber',
        'genre' => 'comedy'
    ],
    [
        'id'    => 2,
        'title' => 'The Mask',
        'genre' => 'comedy'
    ],
];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.