Handle and return response.

@return Response

@throws BadRequestException
486283
public function serve()
    {
        Log::debug('Request received:', [
            'Method'   => $this->request->getMethod(),
            'URI'      => $this->request->getRequestUri(),
            'Query'    => $this->request->getQueryString(),
            'Protocal' => $this->request->server->get('SERVER_PROTOCOL'),
            'Content'  => $this->request->getContent(),
        ]);

        $result = $this->handleRequest();

        $response = $this->buildResponse($result['response']);

        Log::debug('Server response created:', compact('response'));

        return new Response($response);
    }
126125
public function getResponse() {
        $class = $this->getResponseClassName();
        /** @var $response ResponseAbstract */
        $response = new $class;
        $response->setServiceLocator($this->getServiceLocator());
        $response->setException($this->exception)
            ->setHttpCode($this->returnHttpCode)
            ->trace();

        return $response;
    }
652856
public function handle()
    {
        if (! $this->is_ajax_request()) {
            return Handler::DONE;
        }

        $response = [
            'success' => false,
            'data'    => Formatter::formatExceptionAsDataArray($this->getInspector(), $this->addTraceToOutput()),
        ];

        if (Misc::canSendHeaders()) {
            \header('Content-Type: application/json; charset=' . get_option('blog_charset'));
        }

        echo wp_json_encode($response, JSON_PRETTY_PRINT);

        return Handler::QUIT;
    }
1058375
public function handler(): Response
    {
        $data = $this->validate([
            'email' => [
                new Email()
            ],
            'phone' => []
        ]);
        $member = Member::search($this->getParameter('username'));
        if (!$member) {
            throw new HttpNotFoundException();
        }
        $member->update($data);
        $this->log('info', 'Update member [' . $member->getUsername() . ']');
        return response();
    }
883468
public function badRequest(BadRequestException $exception, ServerRequestInterface $request) : ResponseInterface
    {
        $this->exception = $exception;

        $acceptType = $request->getHeader('Accept');
        if (is_array($acceptType) && count($acceptType) > 0 && strpos($acceptType[0], 'json') !== false) {
            return new JsonResponse(['error' => ['message' => 'Bad request sent', 'type' => 'bad_request']], 400);
        }

        if ($this->contentFor400) {
            $this->contentBlock = $this->contentFor400;
        } else {
            $this->contentBlock->addFile(__DIR__ . '/../../../../views/400.php', $this);
        }

        return HtmlResponse::create($this->template, 400);
    }
1253218
public function execute()
    {
        $registered = false;
        if (self::$interceptor_stack === null)
        {
            $registered = true;
            self::registerErrorHandler();
        }
            
        array_push(self::$interceptor_stack, $this);
        $response = null;
        try
        {
            $response = call_user_func_array($this->func, func_get_args());
        }
        finally
        {
            array_pop(self::$interceptor_stack);

            if ($registered)
                self::unregisterErrorHandler();
        }
        return $response;
    }
298863
public function handler(): Response
    {
        $extension = Extension::findBy([
            'vendor' => $this->getParameter('vendor'),
            'package' => $this->getParameter('package')
        ]);
        if (!$extension) {
            throw new HttpForbiddenException();
        }
        $extension->uninstall();
        $this->log('info', 'Uninstall extension [' . $extension->getPackage() . ']');
        return response();
    }
402352
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = Debugger::start($request);
        if ($response !== null) {
            return $response;
        }

        \ob_start();

        try {
            $response = $handler->handle($request);

            if ($this->isError($response->getStatusCode())) {
                throw new HttpErrorException(
                    $response->getReasonPhrase(),
                    $response->getStatusCode()
                );
            }

            return Debugger::writeToResponse($response);
        } catch (\Throwable $exception) {
            return Debugger::exceptionToResponse($exception);
        }
    }
1253926
public function handleRequest()
    {
        try {
            $this->response = parent::handleRequest();
        } catch (HttpException $ex) {
            $this->config->set('page_title', 'Error');

            $view = new View('exception');
            $view->exception = $ex;

            $this->response->setResponseCode($ex->getErrorCode());
            $this->response->setContent($view->render());
        } catch (\Exception $ex) {
            $this->config->set('page_title', 'Error');

            $view = new View('exception');
            $view->exception = $ex;

            $this->response->setResponseCode(500);
            $this->response->setContent($view->render());
        }

        if ($this->response->hasLayout() && $this->controller->layout) {
            $this->setLayoutVariables($this->controller->layout);

            $this->controller->layout->content  = $this->response->getContent();
            $this->response->setContent($this->controller->layout->render());
        }

        return $this->response;
    }
1089269
function response()
    {
        if (!$this->response) {
            $settings = new DataParseResponsePhp;
            $response = new HttpResponse(
                new BuildHttpResponse( BuildHttpResponse::parseWith($settings) )
            );

            $this->response = $response;
        }

        return $this->response;
    }
1103637
public function handler(): Response
    {
        $logoFile = $this->request->files->get('logo');
        $filename = ShortUuid::uuid4() . '.' . $logoFile->guessExtension();
        $directory = app()->getStoragePath() . '/public';
        $logoFile->move($directory, $filename);
        $config = Config::findBy(['key' => 'logo']);
        $config->value('/storage/' . $filename);
        $config->save();
        $this->log('info', 'Upload config.logo to [' . $config->getValue() . ']');
        return response();
    }
519565
public function handler(): Response
    {
        $this->auth(null);
        $data = $this->validate([
            'username' => [
                new NotBlank()
            ],
            'password' => [
                new NotBlank()
            ]
        ]);
        $member = Member::search($data['username']);
        if (!$member) {
            throw new HttpUnauthorizedException();
        }
        if (password_verify($data['password'], $member->getPassword())) {
            $this->auth($member);
            $this->log('info', 'Login successfully');
            return response();
        } else {
            $this->log('info', 'Login failed');
            throw new HttpUnauthorizedException();
        }
    }
1102076
public function handle()
    {
        // get information about the REST-request
        $this->get();

        if ($this->requestMethod === 'GET' && $this->typo3Cache->hasCacheEntry($this->url, $_GET)) {
            return $this->handleRequestByTypo3Cache();
        }

        // if no cache exist: restler should handle the request
        return parent::handle();
    }
913786
public function handler(): Response
    {
        $data = $this->validate([
            'accept' => [
                new Choice(['choices' => [true, false, 0, 1]])
            ],
            'remark' => []
        ]);
        $feedback = BulletinFeedback::find($this->getParameter('id'));
        if (!$feedback) {
            throw new HttpNotFoundException();
        }
        if ($feedback->isChecked() !== null) {
            throw new HttpForbiddenException();
        }
        $feedback->checked(!!$data['accept']);
        $feedback->remark($data['remark']);
        $feedback->save();
        $this->log('info', '[' . $feedback->getReceiver()->getUsername() . '] has feedback for bulletin [' . $feedback->getBulletin()->getId() . ']');
        return response();
    }
1194476
protected function getResponse()
    {
        if ($this->response === null) {
            $this->response = $this->client->send($this->request);
        }

        return $this->response;
    }
469672
public function handler(): Response
    {
        $response = [];
        foreach (Extension::all(['createdAt' => 'ASC']) as $extension) {
            $response[] = [
                'vendor' => $extension->getVendor(),
                'package' => $extension->getPackage(),
                'version' => $extension->getVersion(),
                'description' => $extension->getDescription(),
                'isActivated' => $extension->isActivated()
            ];
        }
        return response($response);
    }
878823
public function getResponse()
    {
        $this->addParameters()->addHeaders();
        $this->options[CURLOPT_RETURNTRANSFER] = true;

        $this->meta = call_user_func($this->map, $this->options);

        return $this->meta['response'];
    }