ChainDecoder.php in Zircon Profile 8.0
File
vendor/symfony/serializer/Encoder/ChainDecoder.php
View source
<?php
namespace Symfony\Component\Serializer\Encoder;
use Symfony\Component\Serializer\Exception\RuntimeException;
class ChainDecoder implements DecoderInterface {
protected $decoders = array();
protected $decoderByFormat = array();
public function __construct(array $decoders = array()) {
$this->decoders = $decoders;
}
public final function decode($data, $format, array $context = array()) {
return $this
->getDecoder($format)
->decode($data, $format, $context);
}
public function supportsDecoding($format) {
try {
$this
->getDecoder($format);
} catch (RuntimeException $e) {
return false;
}
return true;
}
private function getDecoder($format) {
if (isset($this->decoderByFormat[$format]) && isset($this->decoders[$this->decoderByFormat[$format]])) {
return $this->decoders[$this->decoderByFormat[$format]];
}
foreach ($this->decoders as $i => $decoder) {
if ($decoder
->supportsDecoding($format)) {
$this->decoderByFormat[$format] = $i;
return $decoder;
}
}
throw new RuntimeException(sprintf('No decoder found for format "%s".', $format));
}
}
Classes
Name |
Description |
ChainDecoder |
Decoder delegating the decoding to a chain of decoders. |