sinemacula / http-primitives-php
Standalone, framework-agnostic PHP 8.3+ package providing typed backed enums for HTTP protocol primitives with zero runtime dependencies.
v2.0.0
2026-03-15 21:28 UTC
Requires
- php: ^8.3
Requires (Dev)
- brianium/paratest: ^7.8
- friendsofphp/php-cs-fixer: ^3.85
- phpstan/extension-installer: ^1.4
- phpstan/phpdoc-parser: ^2.2
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5.3
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.13
- symfony/http-foundation: ^7.0
This package is auto-updated.
Last update: 2026-03-15 21:30:17 UTC
README
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.