oihana / php-enums
A collection of strongly-typed constant enumerations for PHP
Requires
- php: >=8.4
- oihana/php-core: dev-main
- oihana/php-reflect: dev-main
Requires (Dev)
- mikey179/vfsstream: ^1.6
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^12
README
A collection of strongly-typed constant enumerations for PHP.
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
ConstantsTrait—enums(),includes(),getConstant(),validate()— identical on every class. - 🧩 Composable per-category traits for
HttpHeaderandMailHeader—useonly 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
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ 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-coreoihana/php-reflect– reflection and hydration utilities (providesConstantsTrait):https://github.com/BcommeBois/oihana-php-reflect
