|
@@ -32,6 +32,7 @@ class Serializer implements SerializerInterface
|
|
{
|
|
{
|
|
private $normalizers = array();
|
|
private $normalizers = array();
|
|
private $encoders = array();
|
|
private $encoders = array();
|
|
|
|
+ private $decoders = array();
|
|
protected $normalizerCache = array();
|
|
protected $normalizerCache = array();
|
|
protected $denormalizerCache = array();
|
|
protected $denormalizerCache = array();
|
|
|
|
|
|
@@ -149,9 +150,9 @@ class Serializer implements SerializerInterface
|
|
public function decode($data, $format)
|
|
public function decode($data, $format)
|
|
{
|
|
{
|
|
if (!$this->hasDecoder($format)) {
|
|
if (!$this->hasDecoder($format)) {
|
|
- throw new \UnexpectedValueException('No encoder registered can decode the '.$format.' format');
|
|
|
|
|
|
+ throw new \UnexpectedValueException('No decoder registered for the '.$format.' format');
|
|
}
|
|
}
|
|
- return $this->encoders[$format]->decode($data, $format);
|
|
|
|
|
|
+ return $this->decoders[$format]->decode($data, $format);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -192,6 +193,17 @@ class Serializer implements SerializerInterface
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ */
|
|
|
|
+ public function setDecoder($format, DecoderInterface $decoder)
|
|
|
|
+ {
|
|
|
|
+ $this->decoders[$format] = $decoder;
|
|
|
|
+ if ($decoder instanceof SerializerAwareInterface) {
|
|
|
|
+ $decoder->setSerializer($this);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritdoc}
|
|
* {@inheritdoc}
|
|
*/
|
|
*/
|
|
@@ -200,6 +212,14 @@ class Serializer implements SerializerInterface
|
|
return $this->encoders;
|
|
return $this->encoders;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ */
|
|
|
|
+ public function getDecoders()
|
|
|
|
+ {
|
|
|
|
+ return $this->decoders;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritdoc}
|
|
* {@inheritdoc}
|
|
*/
|
|
*/
|
|
@@ -208,6 +228,14 @@ class Serializer implements SerializerInterface
|
|
return $this->encoders[$format];
|
|
return $this->encoders[$format];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ */
|
|
|
|
+ public function getDecoder($format)
|
|
|
|
+ {
|
|
|
|
+ return $this->decoders[$format];
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritdoc}
|
|
* {@inheritdoc}
|
|
*/
|
|
*/
|
|
@@ -221,7 +249,7 @@ class Serializer implements SerializerInterface
|
|
*/
|
|
*/
|
|
public function hasDecoder($format)
|
|
public function hasDecoder($format)
|
|
{
|
|
{
|
|
- return isset($this->encoders[$format]) && $this->encoders[$format] instanceof DecoderInterface;
|
|
|
|
|
|
+ return isset($this->decoders[$format]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -231,4 +259,12 @@ class Serializer implements SerializerInterface
|
|
{
|
|
{
|
|
unset($this->encoders[$format]);
|
|
unset($this->encoders[$format]);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ */
|
|
|
|
+ public function removeDecoder($format)
|
|
|
|
+ {
|
|
|
|
+ unset($this->decoders[$format]);
|
|
|
|
+ }
|
|
}
|
|
}
|