/** * @return CodecMatcher */ public function getCodecMatcher() { $codecMatcher = new CodecMatcher(); foreach ($this->getEncoders() as $mediaType => $encoder) { $codecMatcher->registerEncoder($this->normalizeMediaType($mediaType), $encoder); } foreach ($this->getDecoders() as $mediaType => $decoder) { $codecMatcher->registerDecoder($this->normalizeMediaType($mediaType), $decoder); } return $codecMatcher; }
/** * @param array $config * @param FactoryInterface $factory * @param ContainerInterface $schemaContainer * * @return CodecMatcherInterface */ protected function createCodecMatcher(array $config, FactoryInterface $factory, ContainerInterface $schemaContainer) { $options = $this->getValue($config, C::JSON, C::JSON_OPTIONS, C::JSON_OPTIONS_DEFAULT); $depth = $this->getValue($config, C::JSON, C::JSON_DEPTH, C::JSON_DEPTH_DEFAULT); $urlPrefix = $this->getValue($config, C::JSON, C::JSON_URL_PREFIX, null); $encoderOptions = new EncoderOptions($options, $urlPrefix, $depth); $decoderClosure = $this->getDecoderClosure(); $encoderClosure = $this->getEncoderClosure($factory, $schemaContainer, $encoderOptions, $config); $codecMatcher = new CodecMatcher(); $jsonApiType = $factory->createMediaType(MediaTypeInterface::JSON_API_TYPE, MediaTypeInterface::JSON_API_SUB_TYPE); $jsonApiTypeUtf8 = $factory->createMediaType(MediaTypeInterface::JSON_API_TYPE, MediaTypeInterface::JSON_API_SUB_TYPE, ['charset' => 'UTF-8']); $codecMatcher->registerEncoder($jsonApiType, $encoderClosure); $codecMatcher->registerDecoder($jsonApiType, $decoderClosure); $codecMatcher->registerEncoder($jsonApiTypeUtf8, $encoderClosure); $codecMatcher->registerDecoder($jsonApiTypeUtf8, $decoderClosure); return $codecMatcher; }