|
@@ -105,7 +105,7 @@ class Serializer implements SerializerInterface
|
|
|
*/
|
|
|
public function encode($data, $format)
|
|
|
{
|
|
|
- if (!isset($this->encoders[$format])) {
|
|
|
+ if (!$this->hasEncoder($format)) {
|
|
|
throw new \UnexpectedValueException('No encoder registered for the '.$format.' format');
|
|
|
}
|
|
|
return $this->encoders[$format]->encode($data, $format);
|
|
@@ -116,7 +116,7 @@ class Serializer implements SerializerInterface
|
|
|
*/
|
|
|
public function decode($data, $format)
|
|
|
{
|
|
|
- if (!isset($this->encoders[$format])) {
|
|
|
+ if (!$this->hasEncoder($format)) {
|
|
|
throw new \UnexpectedValueException('No encoder registered to decode the '.$format.' format');
|
|
|
}
|
|
|
return $this->encoders[$format]->decode($data, $format);
|
|
@@ -138,17 +138,42 @@ class Serializer implements SerializerInterface
|
|
|
unset($this->normalizers[array_search($normalizer, $this->normalizers, true)]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
public function addEncoder($format, EncoderInterface $encoder)
|
|
|
{
|
|
|
$this->encoders[$format] = $encoder;
|
|
|
$encoder->setSerializer($this);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
public function getEncoders()
|
|
|
{
|
|
|
return $this->encoders;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ public function getEncoder($format)
|
|
|
+ {
|
|
|
+ return $this->encoders[$format];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ public function hasEncoder($format)
|
|
|
+ {
|
|
|
+ return isset($this->encoders[$format]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
public function removeEncoder($format)
|
|
|
{
|
|
|
unset($this->encoders[$format]);
|