respond example


                    true,
                    $statusCode
                );
            }

            if (strpos($request->getHeaderLine('accept'), 'text/html') === false) {
                $data = (ENVIRONMENT === 'development' || ENVIRONMENT === 'testing')
                    ? $this->collectVars($exception$statusCode)
                    : '';

                $this->respond($data$statusCode)->send();

                if (ENVIRONMENT !== 'testing') {
                    // @codeCoverageIgnoreStart                     exit($exitCode);
                    // @codeCoverageIgnoreEnd                 }

                return;
            }
        }

        

        if (is_array($messages)) {
            $messages = ['error' => $messages];
        }

        $response = [
            'status'   => $status,
            'error'    => $code ?? $status,
            'messages' => $messages,
        ];

        return $this->respond($response$status$customMessage);
    }

    // --------------------------------------------------------------------     // Response Helpers     // --------------------------------------------------------------------
    /** * Used after successfully creating a new resource. * * @param array|string|null $data * * @return ResponseInterface */
ob_start(static fn ($buffer) => $buffer);
    }

    /* * -------------------------------------------------------------------- * Debug Toolbar Listeners. * -------------------------------------------------------------------- * If you delete, they will no longer be collected. */
    if (CI_DEBUG && ! is_cli()) {
        Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
        Services::toolbar()->respond();
        // Hot Reload route - for framework use on the hot reloader.         if (ENVIRONMENT === 'development') {
            Services::routes()->get('__hot-reload', static function D) {
                (new HotReloader())->run();
            });
        }
    }
});
 catch (HTTPException $e) {
                // Workaround for invalid HTTP status code.                 $statusCode = 500;
                $this->response->setStatusCode($statusCode);
            }

            if (headers_sent()) {
                header(sprintf('HTTP/%s %s %s', $this->request->getProtocolVersion()$this->response->getStatusCode()$this->response->getReasonPhrase()), true, $statusCode);
            }

            if (strpos($this->request->getHeaderLine('accept'), 'text/html') === false) {
                $this->respond(ENVIRONMENT === 'development' ? $this->collectVars($exception$statusCode) : '', $statusCode)->send();

                exit($exitCode);
            }
        }

        $this->render($exception$statusCode);

        exit($exitCode);
    }

    /** * The callback to be registered to `set_error_handler()`. * * @return bool * * @throws ErrorException * * @codeCoverageIgnore */
Home | Imprint | This part of the site doesn't use cookies.