-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4732116
commit e55b865
Showing
2 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Author: Nil Portugués Calderó <contact@nilportugues.com> | ||
* Date: 8/28/15 | ||
* Time: 1:44 AM | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace NilPortugues\Serializer; | ||
|
||
use ReflectionClass; | ||
|
||
|
||
class DeepCopySerializer extends Serializer | ||
{ | ||
/** | ||
* Extract the data from an object. | ||
* | ||
* @param mixed $value | ||
* | ||
* @return array | ||
*/ | ||
protected function serializeObject($value) | ||
{ | ||
if ($this->objectStorage->contains($value)) { | ||
return [self::CLASS_IDENTIFIER_KEY => $this->objectStorage[$value]]; | ||
} | ||
|
||
$this->objectStorage->attach($value, $this->objectMappingIndex++); | ||
|
||
$reflection = new ReflectionClass($value); | ||
$className = $reflection->getName(); | ||
|
||
$serialized = $this->serializeInternalClass($value, $className, $reflection); | ||
$this->objectStorage->attach($value, $serialized); | ||
|
||
return $serialized; | ||
} | ||
|
||
} |
This file contains 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