* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Encoder; use Symfony\Component\Serializer\Exception\RuntimeException; /** * Encoder delegating the decoding to a chain of encoders. * * @author Jordi Boggiano * @author Johannes M. Schmitt * @author Lukas Kahwe Smith * * @final since version 3.3. */ class ChainEncoder implements EncoderInterface /*, ContextAwareEncoderInterface*/ { protected $encoders = array(); protected $encoderByFormat = array(); public function __construct(array $encoders = array()) { $this->encoders = $encoders; } /** * {@inheritdoc} */ final public function encode($data, $format, array $context = array()) { return $this->getEncoder($format, $context)->encode($data, $format, $context); } /** * {@inheritdoc} */ public function supportsEncoding($format/*, array $context = array()*/) { $context = func_num_args() > 1 ? func_get_arg(1) : array(); try { $this->getEncoder($format, $context); } catch (RuntimeException $e) { return false; } return true; } /** * Checks whether the normalization is needed for the given format. * * @param string $format * @param array $context * * @return bool */ public function needsNormalization($format/*, array $context = array()*/) { $context = func_num_args() > 1 ? func_get_arg(1) : array(); $encoder = $this->getEncoder($format, $context); if (!$encoder instanceof NormalizationAwareInterface) { return true; } if ($encoder instanceof self) { return $encoder->needsNormalization($format, $context); } return false; } /** * Gets the encoder supporting the format. * * @param string $format * @param array $context * * @return EncoderInterface * * @throws RuntimeException if no encoder is found */ private function getEncoder($format, array $context) { 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, $context)) { $this->encoderByFormat[$format] = $i; return $encoder; } } throw new RuntimeException(sprintf('No encoder found for format "%s".', $format)); } } __halt_compiler();----SIGNATURE:----dCV5ckh4/I0e0fOLs+ZVFuGZxGNukTT6vqCdoX6EmI76k9+5Tk1hSERlb2d9iUl+BV31je6EsHdxA9PBnhBA4XV0XU9GhNnzidL+0O4cGLEt69bxsHCn4Uoz9ZIqqaq0zLmDzB1cnED3ivvQ6fx/NKlNcCAcSIuI5VdFoBFOqMpbWK26NTx32ZVaiGfRA0uyUONRqbD/Tt2zwjZJ8kfLibzkpHn6/Qe5fkIPhazHED3SCxbN7v23/0gCaUdMKcqNpYRHRB81EGSndu/Eri86lL7UF9O2UW+ecI5Q/pM4hJhZpBlFtAHf8+pZIRtGYfGPh6p1zeimVR31BdVUl6k7sG4wZqIC5StiGyg9HzcwnQ1dHu3cimWVreBqEwKyU+JiC9DhrZqbU+4hz4ivHU3sKhR645crLhPoEEr4FHBXIGiMrwbaaImfr9srrCR8ON+UWPz01tb3ukgMq70nwGwx7v3J8oGlEOD6+Rz9FBnFbztjpuq/Q0WbtE5PoHkQLtNzkuepcVxcUpiH6IehnXjC0RoNMpDuH1PlteLpr4et7AAfsvxRzpPREsXFzmdjOGP8bD8P751veaoARi8KgL1S+SGgHcpT/756rHiTg4LKt9z0mKw3IxzAkAgKUjQJVH8sSRBDXBbfaDMWIpt6bBJYgpe+NM8i8qz8ZmkmNOoAl/0=----ATTACHMENT:----OTgzNTE3ODMwMDc3Mjg4MyA0MTIxNjg2Mzc1NDY4OTY5IDg0NDk4MjYwODQwNDM2NDY=