public function Serializer::normalize

Normalizes an object into a set of arrays/scalars

Parameters

object $object object to normalize:

string $format format the normalization result will be encoded as:

Return value

array|scalar

Overrides NormalizerInterface::normalize

1 call to Serializer::normalize()
Serializer::serialize in drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Serializer.php
Serializes data in the appropriate format

File

drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Serializer.php, line 105

Class

Serializer
Serializer serializes and deserializes data

Namespace

Symfony\Component\Serializer

Code

public function normalize($data, $format = null) {
  if (null === $data || is_scalar($data)) {
    return $data;
  }
  if (is_object($data) && $this
    ->supportsNormalization($data, $format)) {
    return $this
      ->normalizeObject($data, $format);
  }
  if ($data instanceof \Traversable) {
    $normalized = array();
    foreach ($data as $key => $val) {
      $normalized[$key] = $this
        ->normalize($val, $format);
    }
    return $normalized;
  }
  if (is_object($data)) {
    return $this
      ->normalizeObject($data, $format);
  }
  if (is_array($data)) {
    foreach ($data as $key => $val) {
      $data[$key] = $this
        ->normalize($val, $format);
    }
    return $data;
  }
  throw new UnexpectedValueException('An unexpected value could not be normalized: ' . var_export($data, true));
}