Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

jevadebe
Copy link

Hi,

I made several improvements to the library.

  • Fixed an issue where array`s by reference were duplicated.
  • Fixed an issue where static properties where being restored.
  • Created new magic method invoked after creating object, but before restoring data
  • Updated readme

Yours, Jeroen

Copy link
Member

@jrbasso jrbasso left a 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)
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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())
Copy link
Member

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);
Copy link
Member

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] === '[') {
Copy link
Member

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')) {
Copy link
Member

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);
Copy link
Member

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");
Copy link
Member

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 ===.

@young-steveo
Copy link

Closing due to inactivity. @jevadebe let us know if you update per @jrbasso's review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants