Skip to content

Commit

Permalink
made (de)normalizeObject() private
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jun 9, 2011
1 parent d2b9385 commit 715dfcd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Encoder/XmlEncoder.php
Expand Up @@ -254,7 +254,7 @@ private function buildXml($parentNode, $data)
return $append;
}
if (is_object($data)) {
$data = $this->serializer->normalizeObject($data, $this->format);
$data = $this->serializer->normalize($data, $this->format);
if (null !== $data && !is_scalar($data)) {
return $this->buildXml($parentNode, $data);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ private function selectNodeType($node, $val)
} elseif ($val instanceof \Traversable) {
$this->buildXml($node, $val);
} elseif (is_object($val)) {
return $this->buildXml($node, $this->serializer->normalizeObject($val, $this->format));
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
} elseif (is_numeric($val)) {
return $this->appendText($node, (string) $val);
} elseif (is_string($val)) {
Expand Down
17 changes: 13 additions & 4 deletions Serializer.php
Expand Up @@ -119,9 +119,13 @@ public function decode($data, $format)
}

/**
* {@inheritdoc}
* Normalizes an object into a set of arrays/scalars
*
* @param object $object object to normalize
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return array|scalar
*/
public function normalizeObject($object, $format = null)
private function normalizeObject($object, $format = null)
{
if (!$this->normalizers) {
throw new \LogicException('You must register at least one normalizer to be able to normalize objects.');
Expand All @@ -141,9 +145,14 @@ public function normalizeObject($object, $format = null)
}

/**
* {@inheritdoc}
* Denormalizes data back into an object of the given class
*
* @param mixed $data data to restore
* @param string $class the expected class to instantiate
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return object
*/
public function denormalizeObject($data, $class, $format = null)
private function denormalizeObject($data, $class, $format = null)
{
if (!$this->normalizers) {
throw new \LogicException('You must register at least one normalizer to be able to denormalize objects.');
Expand Down
49 changes: 15 additions & 34 deletions SerializerInterface.php
Expand Up @@ -84,33 +84,25 @@ function encode($data, $format);
function decode($data, $format);

/**
* Normalizes an object into a set of arrays/scalars
* Checks whether the serializer can serialize the given format
*
* @param object $object object to normalize
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return array|scalar
* @param string $format format name
* @return Boolean
*/
function normalizeObject($object, $format = null);
function supportsSerialization($format);

/**
* Denormalizes data back into an object of the given class
* Checks whether the serializer can deserialize the given format
*
* @param mixed $data data to restore
* @param string $class the expected class to instantiate
* @param string $format format name, present to give the option to normalizers to act differently based on formats
* @return object
*/
function denormalizeObject($data, $class, $format = null);

/**
* @param NormalizerInterface $normalizer
* @param string $format format name
* @return Boolean
*/
function addNormalizer(NormalizerInterface $normalizer);
function supportsDeserialization($format);

/**
* @param NormalizerInterface $normalizer
* @return EncoderInterface
*/
function removeNormalizer(NormalizerInterface $normalizer);
function getEncoder($format);

/**
* @param string $format format name
Expand All @@ -119,28 +111,17 @@ function removeNormalizer(NormalizerInterface $normalizer);
function setEncoder($format, EncoderInterface $encoder);

/**
* @return EncoderInterface
*/
function getEncoder($format);

/**
* Checks whether the serializer can serialize the given format
*
* @param string $format format name
* @return Boolean
*/
function supportsSerialization($format);
function removeEncoder($format);

/**
* Checks whether the serializer can deserialize the given format
*
* @param string $format format name
* @return Boolean
* @param NormalizerInterface $normalizer
*/
function supportsDeserialization($format);
function addNormalizer(NormalizerInterface $normalizer);

/**
* @param string $format format name
* @param NormalizerInterface $normalizer
*/
function removeEncoder($format);
function removeNormalizer(NormalizerInterface $normalizer);
}

0 comments on commit 715dfcd

Please sign in to comment.