You are here

final public function Serializer::serialize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/Serializer.php \Symfony\Component\Serializer\Serializer::serialize()

Serializes data in the appropriate format.

Parameters

mixed $data any data:

string $format format name:

array $context options normalizers/encoders have access to:

Return value

string

Overrides SerializerInterface::serialize

File

vendor/symfony/serializer/Serializer.php, line 90

Class

Serializer
Serializer serializes and deserializes data.

Namespace

Symfony\Component\Serializer

Code

public final function serialize($data, $format, array $context = array()) {
  if (!$this
    ->supportsEncoding($format)) {
    throw new UnexpectedValueException(sprintf('Serialization for the format %s is not supported', $format));
  }
  if ($this->encoder
    ->needsNormalization($format)) {
    $data = $this
      ->normalize($data, $format, $context);
  }
  return $this
    ->encode($data, $format, $context);
}