Skip to content

Commit

Permalink
[Serializer] Restored docblocks from the deleted methods on Serialize…
Browse files Browse the repository at this point in the history
…rInterface
  • Loading branch information
Seldaek committed May 10, 2011
1 parent de2e535 commit e88f2a9
Showing 1 changed file with 71 additions and 54 deletions.
125 changes: 71 additions & 54 deletions Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,6 @@ public function deserialize($data, $type, $format) {
return $this->denormalize($this->decode($data, $format), $type, $format);
}

/**
* {@inheritdoc}
*/
public function normalizeObject($object, $format = null)
{
if (!$this->normalizers) {
throw new \LogicException('You must register at least one normalizer to be able to normalize objects.');
}
$class = get_class($object);
if (isset($this->normalizerCache[$class][$format])) {
return $this->normalizerCache[$class][$format]->normalize($object, $format);
}
foreach ($this->normalizers as $normalizer) {
if ($normalizer->supportsNormalization($object, $class, $format)) {
$this->normalizerCache[$class][$format] = $normalizer;
return $normalizer->normalize($object, $format);
}
}
throw new \UnexpectedValueException('Could not normalize object of type '.$class.', no supporting normalizer found.');
}

/**
* {@inheritdoc}
*/
public 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.');
}
if (isset($this->denormalizerCache[$class][$format])) {
return $this->denormalizerCache[$class][$format]->denormalize($data, $class, $format);
}
foreach ($this->normalizers as $normalizer) {
if ($normalizer->supportsDenormalization($class, $format)) {
$this->denormalizerCache[$class][$format] = $normalizer;
return $normalizer->denormalize($data, $class, $format);
}
}
throw new \UnexpectedValueException('Could not denormalize object of type '.$class.', no supporting normalizer found.');
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -156,7 +115,57 @@ 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)
{
if (!$this->normalizers) {
throw new \LogicException('You must register at least one normalizer to be able to normalize objects.');
}
$class = get_class($object);
if (isset($this->normalizerCache[$class][$format])) {
return $this->normalizerCache[$class][$format]->normalize($object, $format);
}
foreach ($this->normalizers as $normalizer) {
if ($normalizer->supportsNormalization($object, $class, $format)) {
$this->normalizerCache[$class][$format] = $normalizer;
return $normalizer->normalize($object, $format);
}
}
throw new \UnexpectedValueException('Could not normalize object of type '.$class.', no supporting normalizer found.');
}

/**
* 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)
{
if (!$this->normalizers) {
throw new \LogicException('You must register at least one normalizer to be able to denormalize objects.');
}
if (isset($this->denormalizerCache[$class][$format])) {
return $this->denormalizerCache[$class][$format]->denormalize($data, $class, $format);
}
foreach ($this->normalizers as $normalizer) {
if ($normalizer->supportsDenormalization($class, $format)) {
$this->denormalizerCache[$class][$format] = $normalizer;
return $normalizer->denormalize($data, $class, $format);
}
}
throw new \UnexpectedValueException('Could not denormalize object of type '.$class.', no supporting normalizer found.');
}

/**
* @param NormalizerInterface $normalizer
*/
public function addNormalizer(NormalizerInterface $normalizer)
{
Expand All @@ -167,23 +176,24 @@ public function addNormalizer(NormalizerInterface $normalizer)
}

/**
* {@inheritdoc}
* @return array[]NormalizerInterface
*/
public function getNormalizers()
{
return $this->normalizers;
}

/**
* {@inheritdoc}
* @param NormalizerInterface $normalizer
*/
public function removeNormalizer(NormalizerInterface $normalizer)
{
unset($this->normalizers[array_search($normalizer, $this->normalizers, true)]);
}

/**
* {@inheritdoc}
* @param string $format format name
* @param EncoderInterface $encoder
*/
public function setEncoder($format, EncoderInterface $encoder)
{
Expand All @@ -194,7 +204,8 @@ public function setEncoder($format, EncoderInterface $encoder)
}

/**
* {@inheritdoc}
* @param string $format format name
* @param DecoderInterface $decoder
*/
public function setDecoder($format, DecoderInterface $decoder)
{
Expand All @@ -205,63 +216,69 @@ public function setDecoder($format, DecoderInterface $decoder)
}

/**
* {@inheritdoc}
* @return array[]EncoderInterface
*/
public function getEncoders()
{
return $this->encoders;
}

/**
* {@inheritdoc}
* @return array[]DecoderInterface
*/
public function getDecoders()
{
return $this->decoders;
}

/**
* {@inheritdoc}
* @return EncoderInterface
*/
public function getEncoder($format)
{
return $this->encoders[$format];
}

/**
* {@inheritdoc}
* @return DecoderInterface
*/
public function getDecoder($format)
{
return $this->decoders[$format];
}

/**
* {@inheritdoc}
* Checks whether the serializer has an encoder registered for the given format
*
* @param string $format format name
* @return Boolean
*/
public function hasEncoder($format)
{
return isset($this->encoders[$format]);
}

/**
* {@inheritdoc}
* Checks whether the serializer has a decoder registered for the given format
*
* @param string $format format name
* @return Boolean
*/
public function hasDecoder($format)
{
return isset($this->decoders[$format]);
}

/**
* {@inheritdoc}
* @param string $format format name
*/
public function removeEncoder($format)
{
unset($this->encoders[$format]);
}

/**
* {@inheritdoc}
* @param string $format format name
*/
public function removeDecoder($format)
{
Expand Down

0 comments on commit e88f2a9

Please sign in to comment.