adbario / php-dot-notation Goto Github PK
View Code? Open in Web Editor NEWDot notation access to PHP arrays
License: MIT License
Dot notation access to PHP arrays
License: MIT License
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: 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
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
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()
.
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"
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
Hi,
Is it possible to use wildcards?
Sth. like this: "array.value.*.array.value"
Thank you
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).
It would be nice to be able to unflatten a dot notated array.
$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)
}
}
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']);
}
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"];
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
can we add the ReturnTypeWillChange
attribute?
$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
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.
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'
],
];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.