You are here

private function ChainEncoder::getEncoder in Zircon Profile 8

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

Gets the encoder supporting the format.

Parameters

string $format:

Return value

EncoderInterface

Throws

RuntimeException if no encoder is found

2 calls to ChainEncoder::getEncoder()
ChainEncoder::needsNormalization in vendor/symfony/serializer/Encoder/ChainEncoder.php
Checks whether the normalization is needed for the given format.
ChainEncoder::supportsEncoding in vendor/symfony/serializer/Encoder/ChainEncoder.php
Checks whether the serializer can encode to given format.

File

vendor/symfony/serializer/Encoder/ChainEncoder.php, line 86

Class

ChainEncoder
Encoder delegating the decoding to a chain of encoders.

Namespace

Symfony\Component\Serializer\Encoder

Code

private function getEncoder($format) {
  if (isset($this->encoderByFormat[$format]) && isset($this->encoders[$this->encoderByFormat[$format]])) {
    return $this->encoders[$this->encoderByFormat[$format]];
  }
  foreach ($this->encoders as $i => $encoder) {
    if ($encoder
      ->supportsEncoding($format)) {
      $this->encoderByFormat[$format] = $i;
      return $encoder;
    }
  }
  throw new RuntimeException(sprintf('No encoder found for format "%s".', $format));
}