Skip to content

Instantly share code, notes, and snippets.

@luads
Created March 23, 2017 23:00
Show Gist options
  • Save luads/95f017e7545745182b489936722be226 to your computer and use it in GitHub Desktop.
Save luads/95f017e7545745182b489936722be226 to your computer and use it in GitHub Desktop.
Symfony Serializer Plain PHP Object (stdClass) encoder Raw
<?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