Пример #1
0
 /**
  * Core request handler
  *
  * @param GetResponseEvent $event The event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!count($request->request->all()) && in_array($request->getMethod(), array('POST', 'PUT', 'PATCH', 'DELETE'))) {
         $contentType = $request->headers->get('Content-Type');
         $format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType);
         if (!$this->decoderProvider->supports($format)) {
             return;
         }
         $decoder = $this->decoderProvider->getDecoder($format);
         $data = $decoder->decode($request->getContent(), $format);
         if (is_array($data)) {
             $request->request = new ParameterBag($data);
         }
     }
 }
Пример #2
0
 /**
  * Core request handler
  *
  * @param GetResponseEvent $event The event
  * @throws BadRequestHttpException
  * @throws UnsupportedMediaTypeHttpException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!count($request->request->all()) && in_array($request->getMethod(), array('POST', 'PUT', 'PATCH', 'DELETE'))) {
         $contentType = $request->headers->get('Content-Type');
         $format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType);
         if (!$this->decoderProvider->supports($format)) {
             if ($this->throwExceptionOnUnsupportedContentType) {
                 throw new UnsupportedMediaTypeHttpException("Request body format '{$format}' not supported");
             }
             return;
         }
         $decoder = $this->decoderProvider->getDecoder($format);
         $content = $request->getContent();
         if (!empty($content)) {
             $data = $decoder->decode($content, $format);
             if (is_array($data)) {
                 $request->request = new ParameterBag($data);
             } else {
                 throw new BadRequestHttpException('Invalid ' . $format . ' message received');
             }
         }
     }
 }