Compare commits
8 Commits
c492c52284
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4970d39b13 | |||
| 5c06afc691 | |||
| 5fd843f8c4 | |||
| 63300de69c | |||
| 35e2287053 | |||
| d4da472725 | |||
| 9239bf9eaa | |||
| bf0d20caf9 |
@@ -18,7 +18,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate --strict
|
||||
run: composer validate --strict --no-check-lock
|
||||
|
||||
- name: Cache Composer packages
|
||||
id: composer-cache
|
||||
@@ -29,6 +29,12 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-
|
||||
|
||||
- name: Configure GitHub OAuth for Composer
|
||||
if: ${{ env.GH_COMPOSER_TOKEN != '' }}
|
||||
env:
|
||||
GH_COMPOSER_TOKEN: ${{ secrets.GH_COMPOSER_TOKEN }}
|
||||
run: composer config --global github-oauth.github.com ${{ secrets.GH_COMPOSER_TOKEN }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Development
|
||||
Copyright (c) 2026 René Halberstadt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# tez-utils-enum
|
||||
|
||||
[](https://github.com/tezmanian/tez-utils-enum/actions/workflows/php.yml)
|
||||
[](https://packagist.org/packages/tezmanian/utils-enum)
|
||||
[](https://packagist.org/packages/tezmanian/utils-enum)
|
||||
[](LICENSE)
|
||||
|
||||
Composable PHP 8.3 traits that extend native enums with lookup, comparison, navigation, bitmask, label, and collection helpers.
|
||||
|
||||
**Zero dependencies** · **PHPStan level 9** · **MIT**
|
||||
@@ -7,9 +12,11 @@ Composable PHP 8.3 traits that extend native enums with lookup, comparison, navi
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require tez/utils-enum
|
||||
composer require tezmanian/utils-enum
|
||||
```
|
||||
|
||||
Package: [`tezmanian/utils-enum`](https://packagist.org/packages/tezmanian/utils-enum) · Namespace: `Tezmanian\Utils\Enum`
|
||||
|
||||
Requires PHP ≥ 8.3.
|
||||
|
||||
## Traits
|
||||
@@ -31,7 +38,7 @@ Requires PHP ≥ 8.3.
|
||||
Base trait for pure (unit) enums. Use `BackedEnumTrait` instead when your enum has backing values.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\EnumTrait;
|
||||
use Tezmanian\Utils\Enum\EnumTrait;
|
||||
|
||||
enum Status
|
||||
{
|
||||
@@ -78,7 +85,7 @@ Status::toArray(); // ['Draft' => 'Draft', 'Published' => 'Published', 'Archived
|
||||
Extends `EnumTrait` for string- or int-backed enums. Overrides `is()` to match by backing value, and `toArray()` to return `[value => name]`.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
|
||||
enum Color: string
|
||||
{
|
||||
@@ -124,7 +131,7 @@ Bitmask helpers for int-backed enums used as flag sets. Case values must be powe
|
||||
Does not include `BackedEnumTrait` — combine them explicitly if needed.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\BitFlagTrait;
|
||||
use Tezmanian\Utils\Enum\BitFlagTrait;
|
||||
|
||||
enum Permission: int
|
||||
{
|
||||
@@ -168,7 +175,7 @@ Permission::fromBitmask(0); // []
|
||||
Comparison helpers for int-backed enums, comparing cases by their backing values.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\ComparableTrait;
|
||||
use Tezmanian\Utils\Enum\ComparableTrait;
|
||||
|
||||
enum Priority: int
|
||||
{
|
||||
@@ -205,7 +212,7 @@ Navigate to adjacent cases by definition order. Designed for state machines and
|
||||
Order is determined by **definition order** (ordinal), not backing value. Returns `null` at boundaries — no wrap-around.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\StepTrait;
|
||||
use Tezmanian\Utils\Enum\StepTrait;
|
||||
|
||||
enum CheckoutStep
|
||||
{
|
||||
@@ -238,7 +245,7 @@ CheckoutStep::PersonalInfo->prev(); // null (first step)
|
||||
Human-readable labels for enum cases, without any framework dependency. Override `labels()` to supply custom mappings keyed by case name. Falls back to the case name when no label is defined.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\TranslatableTrait;
|
||||
use Tezmanian\Utils\Enum\TranslatableTrait;
|
||||
|
||||
enum UserRole
|
||||
{
|
||||
@@ -280,7 +287,7 @@ UserRole::labelsArray();
|
||||
Collection-style selection helpers. Can be combined with `EnumTrait` or `BackedEnumTrait`. Works with any enum type.
|
||||
|
||||
```php
|
||||
use Tez\Utils\Enum\EnumCollectionTrait;
|
||||
use Tezmanian\Utils\Enum\EnumCollectionTrait;
|
||||
|
||||
enum Suit
|
||||
{
|
||||
@@ -359,6 +366,15 @@ enum Permission: int
|
||||
- PHP 8.3+
|
||||
- No runtime dependencies
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
make build && make install
|
||||
make ci # audit, PHPStan, code style, tests
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
MIT — see [LICENSE](LICENSE).
|
||||
|
||||
Author: René Halberstadt
|
||||
|
||||
+22
-3
@@ -1,16 +1,35 @@
|
||||
{
|
||||
"name": "tez/utils-enum",
|
||||
"name": "tezmanian/utils-enum",
|
||||
"type": "library",
|
||||
"description": " A collection of PHP traits that supercharge native enums with comparison, bit-flag, stepping, collection, and translation helpers — zero dependencies, PHP 8.3+.",
|
||||
"keywords": [
|
||||
"enum",
|
||||
"traits",
|
||||
"flags",
|
||||
"bitflag",
|
||||
"collection",
|
||||
"php"
|
||||
],
|
||||
"homepage": "https://github.com/tezmanian/tez-utils-enum",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "René Halberstadt",
|
||||
"email": "tezmanian@gmail.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/tezmanian/tez-utils-enum/issues",
|
||||
"source": "https://github.com/tezmanian/tez-utils-enum"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Tez\\Utils\\Enum\\": "src/"
|
||||
"Tezmanian\\Utils\\Enum\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tez\\Utils\\Tests\\Enum\\": "tests/"
|
||||
"Tezmanian\\Utils\\Tests\\Enum\\": "tests/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Extends EnumTrait for string- and int-backed enums.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Bitmask helpers for int-backed enums used as flag sets.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Comparison helpers for int-backed enums.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Add-on trait providing collection-style selection helpers for any enum.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Base trait for pure (unit) enums.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Navigation helpers for stepping to the adjacent case by definition order.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Enum;
|
||||
namespace Tezmanian\Utils\Enum;
|
||||
|
||||
/**
|
||||
* Provides human-readable labels for enum cases without any framework dependency.
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
|
||||
// String-backed enum
|
||||
enum Color: string
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tez\Utils\Enum\BitFlagTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\BitFlagTrait;
|
||||
|
||||
enum Permission: int
|
||||
{
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tez\Utils\Enum\ComparableTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\ComparableTrait;
|
||||
|
||||
enum Level: int
|
||||
{
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\EnumCollectionTrait;
|
||||
use Tezmanian\Utils\Enum\EnumCollectionTrait;
|
||||
|
||||
enum Suit: string
|
||||
{
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tez\Utils\Enum\EnumTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\EnumTrait;
|
||||
|
||||
// Pure (unit) enum used across all EnumTrait tests
|
||||
enum Season
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\EnumTrait;
|
||||
use Tez\Utils\Enum\StepTrait;
|
||||
use Tezmanian\Utils\Enum\EnumTrait;
|
||||
use Tezmanian\Utils\Enum\StepTrait;
|
||||
|
||||
enum OrderStatus
|
||||
{
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
namespace Tezmanian\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tez\Utils\Enum\TranslatableTrait;
|
||||
use Tezmanian\Utils\Enum\BackedEnumTrait;
|
||||
use Tezmanian\Utils\Enum\TranslatableTrait;
|
||||
|
||||
enum StatusWithLabels: string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user