if ($encoder instanceof DecoderInterface
) { $decoders[] =
$encoder;
} if ($encoder instanceof EncoderInterface
) { $realEncoders[] =
$encoder;
} if (!
($encoder instanceof EncoderInterface ||
$encoder instanceof DecoderInterface
)) { throw new InvalidArgumentException(sprintf('The class "%s" neither implements "%s" nor "%s".',
get_debug_type($encoder), EncoderInterface::
class, DecoderInterface::
class));
} } $this->encoder =
new ChainEncoder($realEncoders);
$this->decoder =
new ChainDecoder($decoders);
} final public function serialize(mixed
$data, string
$format, array
$context =
[]): string
{ if (!
$this->
supportsEncoding($format,
$context)) { throw new UnsupportedFormatException(sprintf('Serialization for the format "%s" is not supported.',
$format));
} if ($this->encoder->
needsNormalization($format,
$context)) { $data =
$this->
normalize($data,
$format,
$context);
}