Created
May 28, 2015 07:03
-
-
Save magnetik/1815d79e7380c0339e88 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace AppBundle\Utils; | |
use JMS\Serializer\Construction\DoctrineObjectConstructor; | |
use JMS\Serializer\Construction\ObjectConstructorInterface; | |
use JMS\Serializer\Construction\UnserializeObjectConstructor; | |
use JMS\Serializer\DeserializationContext; | |
use JMS\Serializer\Metadata\ClassMetadata; | |
use JMS\Serializer\VisitorInterface; | |
class JMSSerializerDoctrineUnserializeObjectConstructor implements ObjectConstructorInterface | |
{ | |
private $doctrineObjectConstructor; | |
private $unserializeObjectConstructor; | |
public function __construct(DoctrineObjectConstructor $doctrineObjectConstructor, UnserializeObjectConstructor $unserializeObjectConstructor) | |
{ | |
$this->doctrineObjectConstructor = $doctrineObjectConstructor; | |
$this->unserializeObjectConstructor = $unserializeObjectConstructor; | |
} | |
public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context) | |
{ | |
$object = $this->doctrineObjectConstructor->construct($visitor, $metadata, $data, $type, $context); | |
if (!is_object($object)) { | |
return $this->unserializeObjectConstructor->construct($visitor, $metadata, $data, $type, $context); | |
} | |
return $object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment