sinemacula/http-primitives-php

Standalone, framework-agnostic PHP 8.3+ package providing typed backed enums for HTTP protocol primitives with zero runtime dependencies.

Maintainers

Package info

github.com/sinemacula/http-primitives-php

pkg:composer/sinemacula/http-primitives-php

Statistics

Installs: 35

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-03-15 21:28 UTC

README

Latest Stable Version Build Status Maintainability Code Coverage Total Downloads

Standalone, framework-agnostic PHP 8.3+ package providing typed backed enums for HTTP protocol primitives. Zero runtime dependencies.

Enums

Enum Backing Type Cases Description
HttpStatus int 63 All standard HTTP status codes (1xx-5xx)
HttpMethod string 9 HTTP request methods per RFC 9110
MediaType string 43 Common MIME types across 7 categories
HttpHeader string 61 Standard and non-standard HTTP headers
CacheDirective string 16 Cache-Control directive values
AuthScheme string 3 HTTP authentication schemes
Charset string 20 Common character encodings

All enums live under the SineMacula\Http\Enums namespace.

Helper Methods

Each enum includes contextual helper methods:

  • HttpStatus -- getCode(), getStatusLine(), getReasonPhrase(), isInformational(), isSuccess(), isRedirection(), isClientError(), isServerError()
  • HttpMethod -- getVerb(), isSafe(), isIdempotent()
  • MediaType -- getMimeType(), withCharset(), getExtension(), isApplication(), isText(), isMultipart(), isImage(), isAudio(), isVideo(), isFont()
  • HttpHeader -- getName(), isStandard()
  • CacheDirective -- isRequestDirective(), isResponseDirective()
  • Charset -- getEncoding()

Installation

composer require sinemacula/http-primitives-php

Usage

use SineMacula\Http\Enums\Charset;
use SineMacula\Http\Enums\HttpStatus;
use SineMacula\Http\Enums\HttpMethod;
use SineMacula\Http\Enums\MediaType;

// Status code helpers
$status = HttpStatus::from(404);
$status->getCode();          // 404
$status->getStatusLine();    // '404 Not Found'
$status->isClientError();    // true
$status->getReasonPhrase();  // 'Not Found'

// Method safety checks
HttpMethod::GET->isSafe();        // true
HttpMethod::POST->isIdempotent(); // false

// Media type inspection
MediaType::APPLICATION_JSON->isApplication(); // true
MediaType::APPLICATION_JSON->getExtension();  // 'json'

// Content type composition
MediaType::TEXT_CSV->withCharset(Charset::UTF_8); // 'text/csv; charset=utf-8'

Testing

composer test
composer test-coverage
composer check

Contributing

Contributions are welcome via GitHub pull requests.

Security

If you discover a security issue, please contact Sine Macula directly rather than opening a public issue.

License

Licensed under the Apache License, Version 2.0.