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:

array $context Context options for the normalizer:

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