-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize set values when passing objects #9
Conversation
e45f731
to
5094c6e
Compare
@@ -31,41 +31,40 @@ class RootedJsonData | |||
*/ | |||
public function __construct(string $json = "{}", string $schema = "{}") | |||
{ | |||
$decoded = json_decode($json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate before doing anything else. Validate JSON string directly, JsonObject will result in an empty object ({}
) being transformed into an array ([]
).
* | ||
* @return string | ||
*/ | ||
public function pretty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method for returning formatted JSON
@@ -103,7 +112,7 @@ public function get(string $path) | |||
*/ | |||
public function __get(string $path) | |||
{ | |||
return $this->data->get($path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset the magic getter
* | ||
* @return bool | ||
*/ | ||
public function __isset($path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent variable names
A strange behavior inherited from the JsonObeject class means that for an existing RootedJsonData object, setting a property by passing an object, in particular a stdClass resulting from
json_decode
will cause the full object to be stored at that level of the data structure. Validation still works but retrieving the value after setting it will return the same stdObeject, when we would expect anyget()
to retrieve anarray
.By normalizing incoming objects we avoid this inconsistency. See the new
testAddJsonData()
for examples.