Created
March 23, 2017 23:00
-
-
Save luads/95f017e7545745182b489936722be226 to your computer and use it in GitHub Desktop.
Symfony Serializer Plain PHP Object (stdClass) encoder Raw
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 Acme\Serializer\Encoder; | |
use Symfony\Component\Serializer\Encoder\DecoderInterface; | |
use Symfony\Component\Serializer\Encoder\EncoderInterface; | |
class PlainEncoder implements EncoderInterface, DecoderInterface | |
{ | |
const FORMAT = 'plain'; | |
public function encode($data, $format, array $context = array()) | |
{ | |
return json_decode(json_encode($data, JSON_FORCE_OBJECT), false); | |
} | |
public function decode($data, $format, array $context = array()) | |
{ | |
return json_decode(json_encode($data)); | |
} | |
public function supportsEncoding($format) | |
{ | |
return self::FORMAT === $format; | |
} | |
public function supportsDecoding($format) | |
{ | |
return self::FORMAT === $format; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment