|
@@ -1,5 +1,21 @@
|
|
|
<?php
|
|
|
|
|
|
+/*
|
|
|
+ * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
namespace JMS\SerializerBundle\Serializer;
|
|
|
|
|
|
use Symfony\Component\Serializer\SerializerAwareInterface;
|
|
@@ -43,36 +59,49 @@ class Serializer implements SerializerInterface
|
|
|
$this->encoderMap = $encoderMap;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function normalize($data, $format = null)
|
|
|
{
|
|
|
if ($this->nativePhpTypeNormalizer->supportsNormalization($data, $format)) {
|
|
|
return $this->nativePhpTypeNormalizer->normalize($data, $format);
|
|
|
}
|
|
|
|
|
|
- foreach ($this->customObjectNormalizers as $normalizer) {
|
|
|
- if ($normalizer->supportsNormalization($data, $format)) {
|
|
|
- return $normalizer->normalize($data, $format);
|
|
|
+ if ($this->customObjectNormalizers) {
|
|
|
+ foreach ($this->customObjectNormalizers as $normalizer) {
|
|
|
+ if ($normalizer->supportsNormalization($data, $format)) {
|
|
|
+ return $normalizer->normalize($data, $format);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->defaultObjectNormalizer->normalize($data, $format);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function denormalize($data, $type, $format = null)
|
|
|
{
|
|
|
if ($this->nativePhpTypeNormalizer->supportsDenormalization($data, $type, $format)) {
|
|
|
return $this->nativePhpTypeNormalizer->denormalize($data, $type, $format);
|
|
|
}
|
|
|
|
|
|
- foreach ($this->customObjectNormalizers as $normalizer) {
|
|
|
- if ($normalizer->supportsDenormalization($data, $type, $format)) {
|
|
|
- return $normalizer->denormalize($data, $type, $format);
|
|
|
+ if ($this->customObjectNormalizers) {
|
|
|
+ foreach ($this->customObjectNormalizers as $normalizer) {
|
|
|
+ if ($normalizer->supportsDenormalization($data, $type, $format)) {
|
|
|
+ return $normalizer->denormalize($data, $type, $format);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->defaultObjectNormalizer->denormalize($data, $type, $format);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function serialize($data, $format)
|
|
|
{
|
|
|
$data = $this->normalize($data, $format);
|
|
@@ -80,6 +109,9 @@ class Serializer implements SerializerInterface
|
|
|
return $this->encode($data, $format);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function deserialize($data, $type, $format)
|
|
|
{
|
|
|
$data = $this->decode($data, $format);
|
|
@@ -87,11 +119,17 @@ class Serializer implements SerializerInterface
|
|
|
return $this->denormalize($data, $type, $format);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function encode($data, $format)
|
|
|
{
|
|
|
return $this->getEncoder($format)->encode($data, $format);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public final function decode($data, $format)
|
|
|
{
|
|
|
return $this->getEncoder($format)->decode($data, $format);
|