PHPackages                             philharmony/http-enum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. philharmony/http-enum

ActiveLibrary[HTTP &amp; Networking](/categories/http)

philharmony/http-enum
=====================

Type-safe HTTP enums for methods, status codes, headers, content types, schemes, caching and protocol utilities

v1.3.0(2mo ago)1366↑80.6%2MITPHPPHP ^8.1CI passing

Since Feb 16Pushed 2mo agoCompare

[ Source](https://github.com/philharmonytech/http-enum)[ Packagist](https://packagist.org/packages/philharmony/http-enum)[ Docs](https://github.com/philharmonytech/http-enum)[ RSS](/packages/philharmony-http-enum/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (2)

philharmony/http-enum
=====================

[](#philharmonyhttp-enum)

[![Validate](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml/badge.svg?job=validate)](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml)[![Static Analysis](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml/badge.svg?job=static-analysis)](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml)[![Test](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml/badge.svg?job=tests)](https://github.com/philharmonytech/http-enum/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/ed19836a7f73a31b69770651f09df0ef484ad48bc48df7c70c533ea02ec3408d/68747470733a2f2f636f6465636f762e696f2f6769746875622f7068696c6861726d6f6e79746563682f687474702d656e756d2f67726170682f62616467652e7376673f746f6b656e3d4a56474d31525241434b)](https://codecov.io/github/philharmonytech/http-enum)[![PHP Version](https://camo.githubusercontent.com/48b43ec8db6cfdd0d482cba4d9f310ad8aacc1dadd96ddda95bf9c2daad8bd52/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e31253230746f253230382e342d3838393242462e737667)](https://www.php.net/supported-versions.php)[![Latest Stable Version](https://camo.githubusercontent.com/5c2d50e2a9166efe501c021338011199583bea88405bece31203babc4e33149c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7068696c6861726d6f6e79746563682f687474702d656e756d3f6c6162656c3d737461626c65)](https://github.com/philharmonytech/http-enum/releases)[![Total Downloads](https://camo.githubusercontent.com/733210990015ce5924538357910511c3aa0d0c926e258570094fc65efeee4ac3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068696c6861726d6f6e792f687474702d656e756d)](https://packagist.org/packages/philharmony/http-enum)[![License](https://camo.githubusercontent.com/28ff9723d23f5b0c92f3ddf4eb6a2560f73c6bb9b09576c207b7e1c739961338/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068696c6861726d6f6e792f687474702d656e756d)](https://github.com/philharmonytech/http-enum/blob/main/LICENSE)

Type-safe HTTP enums for PHP: methods, status codes, headers, content types, schemes and protocol utilities — designed for modern applications and libraries.

📖 Description
-------------

[](#-description)

`philharmony/http-enum` provides a set of **strictly typed, PSR-compliant enums** for common HTTP concepts:

- `HttpMethod` — standard HTTP request methods
- `StatusCode` — HTTP status codes with semantic grouping
- `ContentType` — common media types for responses and requests
- `Scheme` — URI schemes with default port mapping (RFC 3986 compliant)
- `HttpHeader` — common HTTP headers with semantic grouping and utilities
- `AuthScheme` — HTTP authentication schemes (Basic, Bearer, Digest, OAuth, etc.)
- `HttpVersion` — HTTP protocol versions with parsing utilities
- `CacheDirective` — Cache-Control directives for HTTP caching behavior
- `ContentEncoding` — HTTP compression algorithms (gzip, br, deflate, etc.)
- `SameSite` — cookie SameSite policies for cross-site request protection

Built for **clean, expressive, and safe code**, this lightweight library requires **PHP 8.1+** and has **zero runtime dependencies**.
It is ideal for **frameworks, middleware, SDKs, and reusable components**.

📚 Included Enums
----------------

[](#-included-enums)

- `HttpMethod`
- `StatusCode`
- `ContentType`
- `Scheme`
- `HttpHeader`
- `AuthScheme`
- `HttpVersion`
- `CacheDirective`
- `ContentEncoding`
- `SameSite`

✨ Why Use This Library?
-----------------------

[](#-why-use-this-library)

Working with HTTP often involves raw strings and magic numbers:

```
if ($method === 'POST') { ... }
if ($status >= 400) { ... }
if ($header === 'Content-Type') { ... }
```

This library replaces them with **type-safe enums:**

```
if ($method === HttpMethod::POST) { ... }
if ($status->isError()) { ... }
if ($header === HttpHeader::CONTENT_TYPE) { ... }
```

Benefits:

- ✅ Type safety — eliminates invalid values
- ✅ Better IDE autocompletion
- ✅ Self-documenting code
- ✅ RFC-aligned semantics
- ✅ Zero runtime dependencies

🚀 Features
----------

[](#-features)

- 🧩 10 HTTP enums
- ⚡ Zero dependencies
- 🧬 Strict typing
- 🔌 Framework agnostic
- 🧠 Semantic helper methods
- 📏 RFC-aligned behavior
- ✅ Fully tested
- 🧰 Developer-friendly utilities

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require philharmony/http-enum
```

⚙️ Requirements
---------------

[](#️-requirements)

- PHP 8.1 or higher

🛠 Usage
-------

[](#-usage)

### HTTP Methods

[](#http-methods)

```
use Philharmony\Http\Enum\HttpMethod;

$method = HttpMethod::POST;

if ($method->isSafe()) { /* Handle GET, HEAD... */ }
if ($method->isIdempotent()) { /* Handle PUT, DELETE... */ }
if ($method->isCacheable()) { /* Handle GET, HEAD */ }
if ($method->isReadOnly()) { /* Handle GET, HEAD, OPTIONS, TRACE */ }
if ($method->isWriteOnly()) { /* Handle POST, PUT, PATCH, DELETE, CONNECT */ }
if ($method->usuallyHasBody()) { /* POST, PUT, PATCH -> true, other false */ }
if ($method->allowsBody()) { /* POST, PUT, PATCH, DELETE -> true, other false */ }
```

### Status Codes

[](#status-codes)

```
use Philharmony\Http\Enum\StatusCode;

$status = StatusCode::NOT_FOUND;

if ($status->isInformational()) { /* 1xx */ }
if ($status->isSuccess()) { /* 2xx */ }
if ($status->isRedirection()) { /* 3xx */ }
if ($status->isClientError()) { /* 4xx */ }
if ($status->isServerError()) { /* 5xx */ }
if ($status->isError()) { /* 4xx and 5xx */ }
if ($status->isCacheable()) { /* Cacheable by default (RFC 9111) */ }
if ($status->statusClass() === 4) { /* client error */ }
if ($status->category() === 'server_error') { /* 5xx */ }
if ($status->phrase() === 'Not Found') { /* Semantic phrases */ }

echo StatusCode::NOT_FOUND->toStatusLine(); // 404 Not Found
```

### Content Types

[](#content-types)

```
use Philharmony\Http\Enum\ContentType;

$contentType = ContentType::JSON;
header('Content-Type: ' . $contentType->value);

if ($contentType->isTextBased()) { /* Handle text-like responses (JSON, HTML, etc.) */ }
if ($contentType->isJson()) { /* Handle json types */ }
if ($contentType->isXml()) { /* Handle xml types */ }
if ($contentType->isImage()) { /* Handle image types */ }
if ($contentType->isAudio()) { /* Handle audio types */ }
if ($contentType->isVideo()) { /* Handle video types */ }
if ($contentType->isMedia()) { /* Handle audio, video and image types */ }
if ($contentType->isFont()) { /* Handle font types */ }
if ($contentType->isForm()) { /* Handle for form types */ }
if ($contentType->isBinary()) { /* Handle for binary types */ }
if ($contentType->isScript()) { /* Handle for script type */ }
if ($contentType->isArchive()) { /* Handle for archive type */ }
if ($contentType->isCompressible()) { /* Enable gzip/br compression */ }

$type = ContentType::fromHeader('application/json; charset=utf-8');
if ($type?->isJson()) { /* Handle JSON */ }

$type = ContentType::fromExtension('txt');
header('Content-Type: ' . $type->value);

$type = ContentType::fromExtension('.json');
header('Content-Type: ' . $type->value);

$type = ContentType::fromFilename('image.png');
header('Content-Type: ' . $type->value);

echo ContentType::JSON->baseType(); // 'json'
echo ContentType::MP4->category(); // 'video'
echo ContentType::JSON->is('application/json'); // true
echo ContentType::JSON->is('APPLICATION/JSON'); // true
echo ContentType::JSON->matches('application/*');  // true
echo ContentType::PNG->matches('image/*');        // true

$best = ContentType::negotiate(
    'application/json, text/html;q=0.9',
    [ContentType::JSON, ContentType::HTML, ContentType::XML]
);
```

### URI Schemes &amp; Ports

[](#uri-schemes--ports)

```
use Philharmony\Http\Enum\Scheme;

$scheme = Scheme::HTTPS;
echo $scheme->defaultPort(); // 443

if ($scheme->isSecure()) { /* Logic for secure connection (SSL/TLS) */ }
if ($scheme->requiresHost()) { /* Logic for requires host */ }
if ($scheme->isHttp()) { /* Handle HTTP, HTTPS */ }
if ($scheme->isWebSocket()) { /* Handle WS, WSS */ }
if ($scheme->isMail()) { /* Handle IMAP, POP, SMTP */ }
if ($scheme->isLdap()) { /* Handle LDAP, LDAPS */ }
```

### HTTP Headers

[](#http-headers)

```
use Philharmony\Http\Enum\HttpHeader;

$header = HttpHeader::CONTENT_TYPE;

if ($header->isContentHeader()) { /* Handle content headers */ }
if ($header->isCacheHeader()) { /* Handle caching logic */ }
if ($header->isAuthHeader()) { /* Handle authentication */ }
if ($header->isSecurityHeader()) { /* Sensitive headers */ }
if ($header->isCors()) { /* CORS headers */ }
if ($header->isProxy()) { /* Proxy / forwarded headers */ }
if ($header->isConditional()) { /* Conditional requests */ }

$header = HttpHeader::fromString('content-type');

echo $header->value; // Content-Type

// HttpHeader::X_FORWARDED_FOR
$header = HttpHeader::tryFromString('x-forwarded-for');
```

### Authentication Schemes

[](#authentication-schemes)

```
use Philharmony\Http\Enum\AuthScheme;

$scheme = AuthScheme::fromHeader('Bearer token123');

if ($scheme?->isTokenBased()) { /* Handle Bearer or OAuth tokens */ }
if ($scheme?->isPasswordBased()) { /* Handle Basic or Digest authentication */ }
if ($scheme?->isChallengeBased()) { /* Handle challenge-response auth */ }

$scheme = AuthScheme::fromString('basic'); // AuthScheme::BASIC
```

### HTTP Versions

[](#http-versions)

```
use Philharmony\Http\Enum\HttpVersion;

$version = HttpVersion::HTTP_1_1;

echo $version->toProtocolString(); // HTTP/1.1

$version = HttpVersion::fromProtocol('HTTP/2');

if ($version === HttpVersion::HTTP_2) { /* HTTP/2 logic */ }

$version = HttpVersion::tryFromString('1.1');
```

### Cache-Control Directives

[](#cache-control-directives)

```
use Philharmony\Http\Enum\CacheDirective;

$directive = CacheDirective::MAX_AGE;

if ($directive->isExpiration()) { /* max-age, s-maxage */ }
if ($directive->isRestriction()) { /* no-cache, no-store */ }
if ($directive->isVisibility()) { /* public, private */ }

$directive = CacheDirective::fromString('no-cache');
echo $directive->value; // no-cache

$directive = CacheDirective::tryFromString('public');
```

### Content Encoding

[](#content-encoding)

```
use Philharmony\Http\Enum\ContentEncoding;

$encoding = ContentEncoding::fromString('gzip');

if ($encoding->isCompressed()) { /* Handle compressed response */ }

$encoding = ContentEncoding::tryFromString('br');
```

### SameSite Cookie Policy

[](#samesite-cookie-policy)

```
use Philharmony\Http\Enum\SameSite;

$sameSite = SameSite::STRICT;

if ($sameSite->isStrict()) { /* Strict cookie policy */ }
if ($sameSite->allowsCrossSite()) { /* Allows cross-site cookies */ }

$sameSite = SameSite::fromString('lax');

$sameSite = SameSite::tryFromString('none');
```

✨ Enum Methods
--------------

[](#-enum-methods)

Each enum provides a set of utility methods for semantic checks, parsing, and grouping — enabling expressive, safe, and framework-agnostic HTTP handling.

### 🏷️ `HttpMethod`

[](#️-httpmethod)

Represents standard HTTP request methods as a backed enum (`string`).

MethodDescription`isSafe(): bool`Returns `true` for safe methods: `GET`, `HEAD`, `OPTIONS`, `TRACE``isIdempotent(): bool`Returns `true` for idempotent methods: `GET`, `HEAD`, `PUT`, `DELETE`, `OPTIONS`, `TRACE`, `CONNECT``isCacheable(): bool`Returns `true` for cacheable methods: `GET`, `HEAD``isReadOnly(): bool`Returns `true` for read only methods: `GET`, `HEAD`, `OPTIONS`, `TRACE``isWriteOnly(): bool`Returns `true` for write only methods: `POST`, `PUT`, `PATCH`, `DELETE`, `CONNECT``usuallyHasBody(): bool`Returns true for methods that typically include a request body: `POST`, `PUT`, `PATCH``allowsBody(): bool`Returns `true` for write only methods: `POST`, `PUT`, `PATCH`, `DELETE``isValid(string $method): bool`Checks if the given string is a valid HTTP method (case-sensitive)`fromString(string $value)`Creates an instance from a valid method string - used strtoupper for value and from()`tryFromString(string $value)`Creates an instance from a valid method string - used strtoupper for value and tryFrom()`from(string $value)`Built-in (PHP 8.1+) — creates an instance from a valid method string`tryFrom(string $value)`Built-in (PHP 8.1+) — returns `null` if invalid> Example: `HttpMethod::isValid('POST')` → `true`Example: `HttpMethod::tryFromString('post')` → `HttpMethod::POST`

---

### 🔢 `StatusCode`

[](#-statuscode)

Represents HTTP status codes as a backed enum (`int`) with semantic grouping and standard reason phrases.

MethodDescription`isInformational(): bool``1xx` (100–199)`isSuccess(): bool``2xx` (200–299)`isRedirection(): bool``3xx` (300–399)`isClientError(): bool``4xx` (400–499)`isServerError(): bool``5xx` (500–599)`isError(): bool``4xx` or `5xx` — indicates an error condition`phrase(): string`Returns the standard reason phrase (e.g., `OK` → `"OK"`, `I_M_A_TEAPOT` → `"I'm a teapot"`)`toStatusLine(): string`Returns full status line fragment like `404 Not Found``from(int $code)`Built-in — creates from status code`tryFrom(int $code)`Built-in — returns `null` if invalid#### Static Group Methods (return `StatusCode[]`):

[](#static-group-methods-return-statuscode)

- `informational()` — all `1xx`
- `success()` — all `2xx`
- `redirection()` — all `3xx`
- `clientError()` — all `4xx`
- `serverError()` — all `5xx`
- `error()` — all `4xx` and `5xx`

> Example: `StatusCode::NOT_FOUND->isClientError()` → `true`

---

### 📝 `ContentType`

[](#-contenttype)

Represents media types as a backed enum (`string`) with parsing and detection utilities.

MethodDescription`isTextBased(): bool``text/*`, `application/json`, `application/xml`, `application/javascript`, etc.`isJson(): bool``application/json`, `application/hal+json`, `application/problem+json`, etc.`isXml(): bool``application/xml`, `application/atom+xml`, `application/rss+xml`, `application/xhtml+xml`, etc.`isImage(): bool``image/*``isAudio(): bool``audio/*``isVideo(): bool``video/*``isMedia(): bool``image/*`, `audio/*`, `video/*``isFont(): bool``font/woff`, `font/woff2`, `font/ttf`, `font/otf``isForm(): bool``application/x-www-form-urlencoded`, `multipart/form-data``isBinary(): bool`Includes media, fonts, PDF, ZIP, Protobuf, etc.`isScript(): bool``application/javascript``isArchive(): bool``application/zip``isCompressible(): bool`Returns `true` for types suitable for compression`defaultCharset(): ?string`Returns default charset for text-like types (heuristic)`baseType(): string`Returns base subtype (e.g. `application/json` → `json`)`category(): string`Returns MIME category (e.g. `json`, `image`, `video`, `audio`, `text`)`is(): bool`Case-insensitive exact match for MIME type`matches(): bool`Pattern match like `image/*`, `application/*``fromHeader(string $header): ?self`Parses from `Content-Type` header (ignores parameters like `; charset=utf-8`)`fromExtension(string $extension): ?self`Maps file extension (e.g., `.json`, `.png`) to content type`fromFilename(string $filename): ?self`Maps filename to content type by extension`negotiate(string $accept, array $available): ?self`Chooses best type from `Accept` header (q + specificity)`from(string $value)`Built-in — creates from MIME type`tryFrom(string $value)`Built-in — returns `null` if invalid#### Static Group Methods (return `ContentType[]`):

[](#static-group-methods-return-contenttype)

- `textBased()`,
- `json()`,
- `xml()`,
- `image()`,
- `audio()`,
- `video()`,
- `media()`,
- `font()`,
- `form()`,
- `binary()`

> Example: `ContentType::fromHeader('application/json; charset=utf-8')` → `ContentType::JSON`

### 🌍 `Scheme`

[](#-scheme)

Represents URI schemes as a backed enum (string) with port mapping.

MethodDescription`defaultPort(): ?int`Returns standard port (e.g., `HTTP` → `80`, `HTTPS` → `443`, `LDAPS` → `636`)`isSecure(): bool`Returns `true` for secure protocols: `HTTPS`, `WSS`, `SFTP`, `LDAPS`, `SSH``requiresHost(): bool`Returns `true` for schemes that require a host: `HTTP`, `HTTPS`, `WS`, `WSS`, `FTP`, `SFTP``isHttp(): bool`Returns `true` for `HTTP`, `HTTPS``isWebSocket(): bool`Returns `true` for `WS`, `WSS``isMail(): bool`Returns `true` for `SMTP`, `IMAP`, `POP``isLdap(): bool`Returns `true` for `LDAP`, `LDAPS``fromString(string $scheme)`Creates enum from scheme string (case-insensitive, trims input)`tryFromString(string $scheme)`Safe version returning `null` if invalid### 📨 `HttpHeader`

[](#-httpheader)

Represents common HTTP headers as a backed enum (`string`) with semantic grouping and normalization utilities.

MethodDescription`isRequestHeader(): bool`Returns `true` if header is typically used in HTTP requests`isResponseHeader(): bool`Returns `true` if header is typically used in HTTP responses`isContentHeader(): bool``Content-*` headers (`Content-Type`, `Content-Length`, etc.)`isCors(): bool``Access-Control-*` headers`isProxy(): bool`Proxy headers (`X-Forwarded-*`, `X-Real-IP`)`isCacheHeader(): bool`Cache-related headers (`Cache-Control`, `ETag`, `Expires`, etc.)`isAuthHeader(): bool`Authentication headers (`Authorization`, `WWW-Authenticate`, etc.)`isSecurityHeader(): bool`Security-sensitive headers (`Authorization`, `Cookie`, `Set-Cookie`)`isConditional(): bool`Conditional request headers (`If-Match`, `If-None-Match`, etc.)`isGeneralHeader(): bool`General headers (`Cache-Control`, `Connection`, `Date`, etc.)`isRequestOnly(): bool`Returns `true` if header is request-only (excludes response/general)`isResponseOnly(): bool`Returns `true` if header is response-only (excludes general)`isHopByHop(): bool`Hop-by-hop headers (RFC 7230, includes `TE` and `Trailer`)`fromString(string $header): self`Creates enum from header name (case-insensitive, trims input)`tryFromString(string $header): ?self`Safe version returning `null` if header is unknown`from(string $value)`Built-in — creates from header string`tryFrom(string $value)`Built-in — returns `null` if invalid> Example: `HttpHeader::fromString('content-type')` → `HttpHeader::CONTENT_TYPE`Example: `HttpHeader::isRequestOnly()` / `HttpHeader::isResponseOnly()` for request/response-only checks

### 🔐 `AuthScheme`

[](#-authscheme)

Represents HTTP authentication schemes used in the `Authorization` and `WWW-Authenticate` headers.

MethodDescription`isTokenBased(): bool`Returns `true` for token-based authentication (`Bearer`, `OAuth`)`isChallengeBased(): bool`Returns `true` for challenge-response schemes (`Basic`, `Digest`, `Negotiate`, `HOBA`, `Mutual`)`isPasswordBased(): bool`Returns `true` for password-based schemes (`Basic`, `Digest`)`fromHeader(string $header): ?self`Extracts authentication scheme from `Authorization` header (case-insensitive)`fromString(string $scheme)`Creates enum from scheme name (case-insensitive, trims input)`tryFromString(string $scheme)`Same as above but returns `null` if invalid`from(string $value)`Built-in — creates enum from valid string`tryFrom(string $value)`Built-in — returns `null` if invalid> Example: `AuthScheme::fromHeader('Bearer token123')` → `AuthScheme::BEARER`Example: `AuthScheme::fromString('basic')` → `AuthScheme::BASIC`

### 🌐 `HttpVersion`

[](#-httpversion)

Represents HTTP protocol versions.

### ✅ `StatusCode` Helpers

[](#-statuscode-helpers)

MethodDescription`statusClass(): int`Returns the status code class (1..5)`category(): string`Returns semantic category (`success`, etc.)`isCacheable(): bool`Returns `true` if cacheable by default (RFC 9111)MethodDescription`toProtocolString(): string`Returns protocol string like `HTTP/1.1`, `HTTP/2``fromProtocol(string $protocol)`Parses version from protocol string (`HTTP/1.1`, `HTTP/2`)`fromString(string $version)`Creates enum from version string (`1.1`, `2`, `3`)`tryFromString(string $version)`Safe version returning `null` if invalid`from(string $value)`Built-in — creates enum from version string`tryFrom(string $value)`Built-in — returns `null` if invalid> Example: `HttpVersion::fromProtocol('HTTP/1.1')` → `HttpVersion::HTTP_1_1`

### 🗄️ `CacheDirective`

[](#️-cachedirective)

Represents `Cache-Control` directives used to control HTTP caching behavior.

MethodDescription`isRestriction(): bool`Returns `true` for cache restrictions (`no-cache`, `no-store`)`isExpiration(): bool`Returns `true` for expiration directives (`max-age`, `s-maxage`)`isVisibility(): bool`Returns `true` for cache visibility (`public`, `private`)`fromString(string $directive)`Creates enum from directive string (case-insensitive)`tryFromString(string $directive)`Safe version returning `null` if directive is unknown`from(string $value)`Built-in — creates enum from valid string`tryFrom(string $value)`Built-in — returns `null` if invalid> Example: `CacheDirective::fromString('no-cache')` → `CacheDirective::NO_CACHE`

### 🗜 `ContentEncoding`

[](#-contentencoding)

Represents compression algorithms used in `Content-Encoding` and `Accept-Encoding` headers.

MethodDescription`isCompressed(): bool`Returns `true` for compression algorithms (all except `identity`)`fromString(string $encoding)`Creates enum from encoding string`tryFromString(string $encoding)`Safe version returning `null` if invalid`from(string $value)`Built-in — creates enum from valid string`tryFrom(string $value)`Built-in — returns `null` if invalid### 🍪 `SameSite`

[](#-samesite)

Represents cookie SameSite policies used in `Set-Cookie` headers to control cross-site request behavior.

MethodDescription`isStrict(): bool`Returns `true` if policy is `Strict``allowsCrossSite(): bool`Returns `true` if cookies may be sent with cross-site requests`fromString(string $value)`Creates enum from SameSite string`tryFromString(string $value)`Safe version returning `null` if invalid`from(string $value)`Built-in — creates enum from valid string`tryFrom(string $value)`Built-in — returns `null` if invalid📜 RFC Compliance
----------------

[](#-rfc-compliance)

This library follows behavior defined in several HTTP specifications:

- **RFC 9110** — HTTP Semantics
- **RFC 9111** — HTTP Caching
- **RFC 9112** — HTTP/1.1
- **RFC 7231** — HTTP Methods
- **RFC 6265** — HTTP Cookies (SameSite)
- **RFC 6454** — Web Origin Concept

🧪 Testing
---------

[](#-testing)

The package is strictly tested with PHPUnit 10 to ensure full compliance with HTTP standards and RFCs.

### Run Tests

[](#run-tests)

```
composer test
```

### Code Coverage

[](#code-coverage)

```
composer test:coverage
```

🏗️ Static Analysis &amp; Code Style
-----------------------------------

[](#️-static-analysis--code-style)

Verified with PHPStan Level 9 to ensure total type safety and prevent runtime errors.

```
composer phpstan
```

Check and fix code style (PSR-12):

```
composer cs-check
composer cs-fix
```

📄 License
---------

[](#-license)

This package is open-source and licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

🤝 Contributing
--------------

[](#-contributing)

Contributions, issues, and feature requests are welcome.

If you find a bug or have an idea for improvement, please open an issue or submit a pull request.

⭐ Support
---------

[](#-support)

If you find this package useful, please consider giving it a star on GitHub. It helps the project grow and reach more developers.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance87

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

5

Last Release

66d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4cd2e09bafc7c15e943d0844b81b7cbfe022c3b13a5cfe59b158e01e11a0658?d=identicon)[it-philharmony](/maintainers/it-philharmony)

---

Top Contributors

[![Vyacheslav86RUS](https://avatars.githubusercontent.com/u/51032800?v=4)](https://github.com/Vyacheslav86RUS "Vyacheslav86RUS (50 commits)")

---

Tags

httppsrphpenumcache-controlstatus codecontent-typesamesitehttp-methodHTTP-headercontent-encoding

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philharmony-http-enum/health.svg)

```
[![Health](https://phpackages.com/badges/philharmony-http-enum/health.svg)](https://phpackages.com/packages/philharmony-http-enum)
```

###  Alternatives

[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

43417.4M104](/packages/kevinrob-guzzle-cache-middleware)[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)[ph-7/just-http-status-codes

Just all HTTP status codes

1447.7k4](/packages/ph-7-just-http-status-codes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
