-
Notifications
You must be signed in to change notification settings - Fork 23
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
Several improvements / Fixes #36
Conversation
…& Ignore static properties
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.
@jevadebe Thanks for the suggestions, but I guess it needs some updates that I pointed inline.
Also, can you make it conform with PSR guidelines?
@@ -245,7 +247,7 @@ public function setUnserializeUndeclaredPropertyMode($value) | |||
* @return mixed | |||
* @throws JsonSerializerException | |||
*/ | |||
protected function serializeData($value) | |||
protected function serializeData(&$value) |
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.
Why to pass the by reference?
@@ -259,18 +261,31 @@ protected function serializeData($value) | |||
throw new JsonSerializerException('Resource is not supported in JsonSerializer'); | |||
} | |||
if (is_array($value)) { | |||
return array_map(array($this, __FUNCTION__), $value); | |||
$id = uniqid(); | |||
$value[$id] = true; |
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.
This would change the passed content since it came as reference. Sounds weird to change it.
static::CLOSURE_IDENTIFIER_KEY => true, | ||
'value' => $this->closureSerializer->serialize($value) | ||
); | ||
return $output; |
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.
Any reason to break down the output? Or is it something left from debugging?
} | ||
return $this->serializeObject($value); | ||
$obj = $this->serializeObject($value); | ||
return $obj; |
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.
Same about breaking down the return.
@@ -320,7 +338,8 @@ protected function getObjectProperties($ref, $value) | |||
|
|||
$props = array(); | |||
foreach ($ref->getProperties() as $prop) { | |||
$props[] = $prop->getName(); | |||
if(!$prop->isStatic()) |
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.
I guess storing or not storing static on the output should be an option on the [de]serialization.
@@ -434,6 +472,13 @@ protected function unserializeObject($value) | |||
return $this->objectMapping[$index]; | |||
} | |||
|
|||
if ($className[0] === '[') { | |||
$index = substr($className, 1, strlen($className) - 2); | |||
// dd($index); |
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.
Remove another debug code.
@@ -434,6 +472,13 @@ protected function unserializeObject($value) | |||
return $this->objectMapping[$index]; | |||
} | |||
|
|||
if ($className[0] === '[') { |
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.
Maybe you should check for the pattern completely to avoid false positives and bad deserialization.
@@ -463,22 +508,54 @@ protected function unserializeObject($value) | |||
return $obj; | |||
} | |||
|
|||
|
|||
if (method_exists($obj, '__wakeupprerestore')) { |
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.
Which method is that? Why to call it? I don't think it's standard.
@@ -214,6 +214,7 @@ public function testUnserializeObjects() | |||
{ | |||
$serialized = '{"@type":"stdClass"}'; | |||
$obj = $this->serializer->unserialize($serialized); | |||
// var_dump($obj); |
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.
Please remove debug code.
|
||
$unserialized->arr[] = "This is arr"; | ||
$unserialized->arr2[] = "This is arr2"; | ||
$this->assertTrue($unserialized->arr_copy[2] === "This is arr"); |
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.
You should be using assertSame
instead using the ===
.
Hi,
I made several improvements to the library.
Yours, Jeroen