src/Handler/HttpHandler.php
public function handleHttpRequest(HttpRequest $httpRequest)
    {
        // @var Event\HttpRequestEvent $event
        $event = $this->dispatch(Event\HttpRequestEvent::EVENT, new Event\HttpRequestEvent($httpRequest));
        $httpRequest = $event->getHttpRequest();

        try {
            $jsonRequests = $this->parserHttpRequest($httpRequest);
        } catch (Exceptions\ParseException  $e) {
            return $this->createHttpResponseFromException($e);
        }

        $jsonResponses = $this->jsonHandler->handleJsonRequest($jsonRequests);
        $httpResponse = HttpResponse::create();

        if ($this->profiler) {
            /**
             * @param JsonResponse|JsonResponse[] $jsonResponse
             */
            $collect = function ($jsonResponse) use (&$collect, $httpRequest, $httpResponse) {
                if (\is_array($jsonResponse)) {
                    foreach ($jsonResponse as $value) {
                        $collect($value);
                    }
                } else {
                    if ($jsonResponse->isError()) {
                        $this->collectException(
                            $httpRequest,
                            $httpResponse,
                            new Exceptions\ErrorException($jsonResponse->getErrorMessage(), $jsonResponse->getErrorCode(), $jsonResponse->getErrorData(), $jsonResponse->getId())
                        );
                    }
                }
            };

            $collect($jsonResponses);
        }

        // Set httpResponse content.

        if (\is_array($jsonResponses)) {
            $results = [];

            foreach ($jsonResponses as $jsonResponse) {
                if ($jsonResponse->isError() || $jsonResponse->getId()) {
                    $results[] = $jsonResponse;
                }

                if ($jsonResponse->isError()) {
                    $httpResponse->setStatusCode($this->errorCode);
                }
            }

            $httpResponse->setContent(\json_encode($results));
        } else {
            if ($jsonResponses->isError() || $jsonResponses->getId()) {
                $httpResponse->setContent(\json_encode($jsonResponses));
            }

            if ($jsonResponses->isError()) {
                $httpResponse->setStatusCode($this->errorCode);
            }
        }

        // Set httpResponse headers
        if (\is_array($jsonResponses)) {
            foreach ($jsonResponses as $jsonResponse) {
                if ($jsonResponse->isError() || $jsonResponse->getId()) {
                    $httpResponse->headers->add($jsonResponse->headers()->all());
                }
            }
        } else {
            $httpResponse->headers->add($jsonResponses->headers()->all());
        }

        $httpResponse->headers->set('Content-Type', 'application/json');

        $this->dispatch(
            Event\HttpResponseEvent::EVENT,
            new Event\HttpResponseEvent($httpResponse)
        );

        return $httpResponse;
    }
public function handleHttpRequest(HttpRequest $httpRequest)
    {
        // @var Event\HttpRequestEvent $event
        $event = $this->dispatch(Event\HttpRequestEvent::EVENT, new Event\HttpRequestEvent($httpRequest));
        $httpRequest = $event->getHttpRequest();

        try {
            $jsonRequests = $this->parserHttpRequest($httpRequest);
        } catch (Exceptions\ParseException  $e) {
            return $this->createHttpResponseFromException($e);
        }

        $jsonResponses = $this->jsonHandler->handleJsonRequest($jsonRequests);
        $httpResponse = HttpResponse::create();

        if ($this->profiler) {
            /**
             * @param JsonResponse|JsonResponse[] $jsonResponse
             */
            $collect = function ($jsonResponse) use (&$collect, $httpRequest, $httpResponse) {
                if (\is_array($jsonResponse)) {
                    foreach ($jsonResponse as $value) {
                        $collect($value);
                    }
                } else {
                    if ($jsonResponse->isError()) {
                        $this->collectException(
                            $httpRequest,
                            $httpResponse,
                            new Exceptions\ErrorException($jsonResponse->getErrorMessage(), $jsonResponse->getErrorCode(), $jsonResponse->getErrorData(), $jsonResponse->getId())
                        );
                    }
                }
            };

            $collect($jsonResponses);
        }

        // Set httpResponse content.

        if (\is_array($jsonResponses)) {
            $results = [];

            foreach ($jsonResponses as $jsonResponse) {
                if ($jsonResponse->isError() || $jsonResponse->getId()) {
                    $results[] = $jsonResponse;
                }

                if ($jsonResponse->isError()) {
                    $httpResponse->setStatusCode($this->errorCode);
                }
            }

            $httpResponse->setContent(\json_encode($results));
        } else {
            if ($jsonResponses->isError() || $jsonResponses->getId()) {
                $httpResponse->setContent(\json_encode($jsonResponses));
            }

            if ($jsonResponses->isError()) {
                $httpResponse->setStatusCode($this->errorCode);
            }
        }

        // Set httpResponse headers
        if (\is_array($jsonResponses)) {
            foreach ($jsonResponses as $jsonResponse) {
                if ($jsonResponse->isError() || $jsonResponse->getId()) {
                    $httpResponse->headers->add($jsonResponse->headers()->all());
                }
            }
        } else {
            $httpResponse->headers->add($jsonResponses->headers()->all());
        }

        $httpResponse->headers->set('Content-Type', 'application/json');

        $this->dispatch(
            Event\HttpResponseEvent::EVENT,
            new Event\HttpResponseEvent($httpResponse)
        );

        return $httpResponse;
    }
Handle http request.

@param HttpRequest $httpRequest

@return HttpResponse