Neuron-PHP

HttpResponseStatus : int
in package

HTTP response status code enumeration for the MVC framework.

This enum provides a comprehensive collection of standard HTTP response status codes as defined in RFC 7231 and related specifications. It enables type-safe status code handling throughout the MVC framework and ensures consistent HTTP response behavior across all controllers and views.

Status code categories:

  • 2xx Success: Request successfully received, understood, and accepted
  • 3xx Redirection: Further action needs to be taken to complete the request
  • 4xx Client Error: Request contains bad syntax or cannot be fulfilled
  • 5xx Server Error: Server failed to fulfill an apparently valid request

Key benefits:

  • Type safety for HTTP status codes
  • IDE auto-completion support
  • Prevention of invalid status code usage
  • Clear semantic meaning for response states
  • Integration with framework response handling
Tags
example
// Using in controller responses
public function create(): Response
{
    try {
        $user = $this->userService->create($userData);
        return $this->response($user, HttpResponseStatus::CREATED);
    } catch (ValidationException $e) {
        return $this->errorResponse('Validation failed', HttpResponseStatus::BAD_REQUEST);
    }
}

// Setting response status
public function show(int $id): Response
{
    $user = $this->userService->find($id);
    if (!$user) {
        return $this->errorResponse('User not found', HttpResponseStatus::NOT_FOUND);
    }
    return $this->response($user, HttpResponseStatus::OK);
}

Table of Contents

Cases

ACCEPTED  = 202
BAD_GATEWAY  = 502
BAD_REQUEST  = 400
CONFLICT  = 409
CREATED  = 201
FORBIDDEN  = 403
FOUND  = 302
GATEWAY_TIMEOUT  = 504
GONE  = 410
HTTP_VERSION_NOT_SUPPORTED  = 505
INTERNAL_SERVER_ERROR  = 500
LENGTH_REQUIRED  = 411
METHOD_NOT_ALLOWED  = 405
MOVED_PERMANENTLY  = 301
NETWORK_AUTHENTICATION_REQUIRED  = 511
NO_CONTENT  = 204
NOT_ACCEPTABLE  = 406
NOT_FOUND  = 404
NOT_IMPLEMENTED  = 501
NOT_MODIFIED  = 304
OK  = 200
PAYLOAD_TOO_LARGE  = 413
PERMANENT_REDIRECT  = 308
PRECONDITION_FAILED  = 412
REQUEST_TIMEOUT  = 408
SEE_OTHER  = 303
SERVICE_UNAVAILABLE  = 503
TEMPORARY_REDIRECT  = 307
TOO_MANY_REQUESTS  = 429
UNAUTHORIZED  = 401
UNSUPPORTED_MEDIA_TYPE  = 415
UPGRADE_REQUIRED  = 426

Cases


        
On this page

Search results