Open
Conversation
setValue method will get different result according to the order of keys, the short key will overwrite the long keys, should check the long key is set, and push the short key.
Author
|
for example $multiArray = new Tebru\MultiArray(array());
$multiArray->set('考.察.队.员', array("end"=>""));
$multiArray->set('考.察.上', array("end"=>""));
$multiArray->set('考.察', array("end"=>""));
var_dump($multiArray);will get: object(Tebru\MultiArray)#4 (3) {
["keyDelimiter":"Tebru\MultiArray":private]=>
string(1) "."
["storage":"Tebru\MultiArray":private]=>
array(1) {
["考"]=>
array(1) {
["察"]=>
array(1) {
["end"]=>
string(0) ""
}
}
}
["cache":"Tebru\MultiArray":private]=>
array(3) {
["考.察.队.员"]=>
array(1) {
["end"]=>
string(0) ""
}
["考.察.上"]=>
array(1) {
["end"]=>
string(0) ""
}
["考.察"]=>
array(1) {
["end"]=>
string(0) ""
}
}
}and when change order: $multiArray = new Tebru\MultiArray(array());
$multiArray->set('考.察', array("end"=>""));
$multiArray->set('考.察.上', array("end"=>""));
$multiArray->set('考.察.队.员', array("end"=>""));
var_dump($multiArray);will get: object(Tebru\MultiArray)#5 (3) {
["keyDelimiter":"Tebru\MultiArray":private]=>
string(1) "."
["storage":"Tebru\MultiArray":private]=>
array(1) {
["考"]=>
array(1) {
["察"]=>
array(3) {
["end"]=>
string(0) ""
["上"]=>
array(1) {
["end"]=>
string(0) ""
}
["队"]=>
array(1) {
["员"]=>
array(1) {
["end"]=>
string(0) ""
}
}
}
}
}
["cache":"Tebru\MultiArray":private]=>
array(3) {
["考.察"]=>
array(1) {
["end"]=>
string(0) ""
}
["考.察.上"]=>
array(1) {
["end"]=>
string(0) ""
}
["考.察.队.员"]=>
array(1) {
["end"]=>
string(0) ""
}
}
} |
Member
|
Could you also update the tests and rebase? |
setValue method will get InvalidArgumentException when set string value to keys according to the order of set value order. Fix this bug then we don’t get InvalidArgumentException anymore.
Author
|
When I write test, I fix another bug: setValue method will get InvalidArgumentException when set string value(not get exception when set array value) to keys according to the order of set value order. Fix this bug then we don’t have to check InvalidArgumentException anymore. For example: $multiArray = new Tebru\MultiArray(array());
$multiArray->set('key1.key2.key3.key4', 'value1');
$multiArray->set('key1.key2.key5', 'value2');
$multiArray->set('key1.key2', 'value3');
var_dump($multiArray);will not get InvalidArgumentException: object(Tebru\MultiArray)#3 (3) {
["keyDelimiter":"Tebru\MultiArray":private]=>
string(1) "."
["storage":"Tebru\MultiArray":private]=>
array(1) {
["key1"]=>
array(1) {
["key2"]=>
array(3) {
["key3"]=>
array(1) {
["key4"]=>
string(6) "value1"
}
["key5"]=>
string(6) "value2"
[0]=>
string(6) "value3"
}
}
}
["cache":"Tebru\MultiArray":private]=>
array(3) {
["key1.key2.key3.key4"]=>
string(6) "value1"
["key1.key2.key5"]=>
string(6) "value2"
["key1.key2"]=>
string(6) "value3"
}
}change the order form short key to long key: $multiArray = new Tebru\MultiArray(array());
$multiArray->set('key1.key2', 'value3');
$multiArray->set('key1.key2.key5', 'value2');
$multiArray->set('key1.key2.key3.key4', 'value1');
var_dump($multiArray);will get InvalidArgumentException: PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Expected array, got string' |
Author
|
@natebrunette I add a simple test case and rebase the repo, and pass the build. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
setValue method will get different result according to the order of
keys, the short key will overwrite the long keys, should check the long
key is set, and push the short key.