oihana/php-enums

A collection of strongly-typed constant enumerations for PHP

Maintainers

Package info

github.com/BcommeBois/oihana-php-enums

Homepage

pkg:composer/oihana/php-enums

Statistics

Installs: 353

Dependents: 16

Suggesters: 0

Stars: 0

Open Issues: 0

1.2.2 2026-06-10 12:11 UTC

This package is auto-updated.

Last update: 2026-06-10 12:13:06 UTC


README

Oihana PHP Enums

A collection of strongly-typed constant enumerations for PHP.

Latest Version Total Downloads License

oihana/php-enums bundles over 1,600 constants across 73 enumeration classes in five domains — general, HTTP, mail/SMTP, JWT/JOSE and OAuth 2.0/OIDC. Every class is a constant class (not a native PHP enum) using ConstantsTrait, so they all share one reflection API — list, validate and reverse-look-up values without instantiating anything, and replace magic strings everywhere.

Framework-agnostic, PHP 8.4+, dependency-light.

📚 Documentation

User guides (FR + EN) — getting started, the shared ConstantsTrait API, the full catalogue per namespace, convenience helpers, testing and tips:

🇬🇧 English documentation 🇫🇷 Documentation française
Getting started, ConstantsTrait, general/HTTP/mail/JWT/OAuth2, helpers, tips. Démarrage, ConstantsTrait, général/HTTP/mail/JWT/OAuth2, helpers, astuces.

Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-enums

🚀 Features

  • 📦 73 enumerations / 1,600+ constants across general, HTTP, mail/SMTP, JWT/JOSE and OAuth 2.0/OIDC domains.
  • 🔍 One shared reflection API via ConstantsTraitenums(), includes(), getConstant(), validate() — identical on every class.
  • 🧩 Composable per-category traits for HttpHeader and MailHeaderuse only what you need.
  • ⚙️ Domain helpers where they help — HttpStatusCode::getDescription(), SmtpSecurity::scheme(), MailPriority::toXPriority(), PostalCodePattern::isValid(), and more.
  • 🛡️ No magic strings — typo-safe, refactor-friendly, IDE-autocompleted.

💡 No external dependencies beyond Oihana's core and reflection utilities.

📦 Installation

Requires PHP 8.4+

Install via Composer:

composer require oihana/php-enums

🚀 Quick start

use oihana\enums\Boolean;
use oihana\enums\Char;
use oihana\enums\http\HttpMethod;
use oihana\enums\http\HttpStatusCode;

$enabled = Boolean::TRUE;                  // 'true'
echo 'A' . Char::DOT . 'B';                // 'A.B'

HttpMethod::includes( 'GET' );             // true
HttpMethod::enums();                       // ['CONNECT', 'DELETE', 'GET', ...]
HttpStatusCode::getDescription( 404 );     // 'Not found'

The full catalogue lives in the wiki — English · Français.

✅ Tests & coverage

Run the full unit-test suite (PHPUnit, strict mode):

composer test

Run a single test case:

./vendor/bin/phpunit --filter HttpStatusCodeTest

Measure coverage (requires Xdebug or PCOV):

composer coverage        # text + Clover + HTML under build/coverage/
composer coverage:md     # readable Markdown summary (build/coverage/COVERAGE.md)

The suite covers 100% of lines (323/323). For the testing philosophy and the @codeCoverageIgnore policy, see wiki/en/testing.md · wiki/fr/testing.md.

🧾 License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).

👤 About the author

🛠️ Generate the documentation

We use phpDocumentor to generate the API reference into the ./docs folder:

composer doc

docs/ is gitignored and published to GitHub Pages by CI — it is not committed.

🔗 Related packages

  • oihana/php-core – core helpers and utilities used by this library: https://github.com/BcommeBois/oihana-php-core
  • oihana/php-reflect – reflection and hydration utilities (provides ConstantsTrait): https://github.com/BcommeBois/oihana-php-reflect