function ChainEncoder::getEncoder
Gets the encoder supporting the format.
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 84
Class
- ChainEncoder
- Encoder delegating the decoding to a chain of encoders.
Namespace
Symfony\Component\Serializer\EncoderCode
private function getEncoder(string $format, array $context) : EncoderInterface {
if (isset($this->encoderByFormat[$format]) && isset($this->encoders[$this->encoderByFormat[$format]])) {
return $this->encoders[$this->encoderByFormat[$format]];
}
$cache = true;
foreach ($this->encoders as $i => $encoder) {
$cache = $cache && !$encoder instanceof ContextAwareEncoderInterface;
if ($encoder->supportsEncoding($format, $context)) {
if ($cache) {
$this->encoderByFormat[$format] = $i;
}
return $encoder;
}
}
throw new RuntimeException(\sprintf('No encoder found for format "%s".', $format));
}