View source
<?php
namespace Drupal\jsonapi_extras;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Drupal\jsonapi\Serializer\Serializer;
class SerializerDecorator implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface {
protected $decoratedSerializer;
protected $isInitialized = FALSE;
public function __construct(Serializer $serializer) {
$this->decoratedSerializer = $serializer;
}
protected function lazilyInitialize() {
if (!$this->isInitialized) {
$core_serializer = \Drupal::service('serializer');
$this->decoratedSerializer
->setFallbackNormalizer($core_serializer);
$this->isInitialized = TRUE;
}
}
protected function relay($method_name, array $args) {
$this
->lazilyInitialize();
return call_user_func_array([
$this->decoratedSerializer,
$method_name,
], $args);
}
public function decode($data, $format, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function denormalize($data, $class, $format = NULL, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function deserialize($data, $type, $format, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function encode($data, $format, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function normalize($object, $format = NULL, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function supportsDecoding($format) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function serialize($data, $format, array $context = []) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function supportsDenormalization($data, $type, $format = NULL) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function supportsEncoding($format) {
return $this
->relay(__FUNCTION__, func_get_args());
}
public function supportsNormalization($data, $format = NULL) {
return $this
->relay(__FUNCTION__, func_get_args());
}
}