forked from csarrazi/CsaGuzzleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serializer Adapter JMS and default Symfony
- Loading branch information
Alexander Janssen
committed
Jun 5, 2015
1 parent
216b227
commit 0d66837
Showing
7 changed files
with
97 additions
and
8 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
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
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
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
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
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
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,62 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: AJanssen | ||
* Date: 05-06-15 | ||
* Time: 15:22 | ||
*/ | ||
|
||
namespace Csa\Bundle\GuzzleBundle\Serializer; | ||
|
||
|
||
use JMS\Serializer\DeserializationContext; | ||
use JMS\Serializer\SerializationContext; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use \JMS\Serializer\SerializerInterface as JMSSerializerInterface; | ||
|
||
class JMSAdapter implements SerializerInterface | ||
{ | ||
/** | ||
* @var JMSSerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @param \JMS\Serializer\SerializerInterface $serializer | ||
*/ | ||
public function __construct(JMSSerializerInterface $serializer) | ||
{ | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* Serializes data in the appropriate format. | ||
* | ||
* @param mixed $data any data | ||
* @param string $format format name | ||
* @param array $context options normalizers/encoders have access to | ||
* | ||
* @return string | ||
*/ | ||
public function serialize($data, $format, array $context = []) | ||
{ | ||
return $this->serializer->serialize($data, $format, SerializationContext::create($context)); | ||
} | ||
|
||
/** | ||
* Deserializes data into the given type. | ||
* | ||
* @param mixed $data | ||
* @param string $type | ||
* @param string $format | ||
* @param array $context | ||
* | ||
* @return object | ||
*/ | ||
public function deserialize($data, $type, $format, array $context = []) | ||
{ | ||
return $this->serializer->deserialize($data, $type, $format, DeserializationContext::create($context)); | ||
} | ||
|
||
|
||
} |