From 21843ce4cc3856c09260422236763ce2a54c3fc8 Mon Sep 17 00:00:00 2001 From: Kangin Kim Date: Thu, 3 Dec 2026 17:40:37 +0900 Subject: [PATCH 1/3] Organize native enum extensions into concept-specific namespaces --- .github/workflows/ci.yml | 2 +- docs/static-analysis/README.md | 2 +- docs/static-analysis/collection-negative.php | 4 ++-- docs/static-analysis/collection-positive.php | 8 ++++---- docs/static-analysis/composite-negative.php | 2 +- docs/static-analysis/composite-positive.php | 18 +++++++++--------- examples/NativeExtension/Backed/ByteUnit.php | 4 ++-- examples/NativeExtension/Backed/Currency.php | 2 +- .../Collections/FilePermission.php | 4 ++-- .../Composite/ConstructionPolicies.php | 6 +++--- .../Composite/EnumComposite.php | 6 +++--- .../Composition/OrderStatusBadge.php | 2 +- .../NativeExtension/External/PaymentStatus.php | 2 +- .../NativeExtension/Inheritance/Permission.php | 2 +- .../Presentation/OrderStatus.php | 4 ++-- .../Strategies/AirmailPostage.php | 4 ++-- .../Strategies/AirmailPostageByEnum.php | 2 +- .../Strategies/AirmailPostageByFactory.php | 2 +- .../Strategies/AirmailPostageByType.php | 2 +- src/{ => Extension/Case}/EnumCase.php | 2 +- .../Collection}/EnumCollection.php | 3 ++- .../Composite}/CompositeDuplicates.php | 2 +- .../Composite}/CompositeOrder.php | 2 +- .../Composite}/EnumComposite.php | 2 +- .../Composite}/EnumCompositeBuilder.php | 2 +- src/Internal/NativeCasePredicate.php | 2 +- tests/NativeCollection/EnumCollectionTest.php | 4 ++-- tests/NativeExtension/EnumCaseTest.php | 2 +- tests/NativeExtension/EnumCompositeTest.php | 6 +++--- tests/NativeTraits/EnumCollectionsTest.php | 4 ++-- 30 files changed, 55 insertions(+), 54 deletions(-) rename src/{ => Extension/Case}/EnumCase.php (99%) rename src/{ => Extension/Collection}/EnumCollection.php (99%) rename src/{ => Extension/Composite}/CompositeDuplicates.php (79%) rename src/{ => Extension/Composite}/CompositeOrder.php (78%) rename src/{ => Extension/Composite}/EnumComposite.php (99%) rename src/{ => Extension/Composite}/EnumCompositeBuilder.php (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cf995b..698646a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,7 +91,7 @@ jobs: - name: Check composite type contracts run: | phpstan analyse --level=max --no-progress --autoload-file=vendor/autoload.php \ - src/EnumComposite.php src/EnumCompositeBuilder.php \ + src/Extension/Composite/EnumComposite.php src/Extension/Composite/EnumCompositeBuilder.php \ examples/NativeExtension/Composite/EnumComposite.php docs/static-analysis/composite-positive.php status=0 phpstan analyse --level=max --no-progress --error-format=json --autoload-file=vendor/autoload.php \ diff --git a/docs/static-analysis/README.md b/docs/static-analysis/README.md index ae67e8f..71dad6d 100644 --- a/docs/static-analysis/README.md +++ b/docs/static-analysis/README.md @@ -45,7 +45,7 @@ The composite check analyses the implementation, executable example and positive ```sh phpstan analyse --level=max --autoload-file=vendor/autoload.php \ - src/EnumComposite.php src/EnumCompositeBuilder.php \ + src/Extension/Composite/EnumComposite.php src/Extension/Composite/EnumCompositeBuilder.php \ examples/NativeExtension/Composite/EnumComposite.php docs/static-analysis/composite-positive.php phpstan analyse --level=max --autoload-file=vendor/autoload.php docs/static-analysis/composite-negative.php ``` diff --git a/docs/static-analysis/collection-negative.php b/docs/static-analysis/collection-negative.php index 01cdb6b..7d8e264 100644 --- a/docs/static-analysis/collection-negative.php +++ b/docs/static-analysis/collection-negative.php @@ -4,8 +4,8 @@ namespace EnumExStaticAnalysisNegative; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum Status { case Paid; diff --git a/docs/static-analysis/collection-positive.php b/docs/static-analysis/collection-positive.php index 0abd9db..1a3d741 100644 --- a/docs/static-analysis/collection-positive.php +++ b/docs/static-analysis/collection-positive.php @@ -5,8 +5,8 @@ namespace EnumExStaticAnalysis; use Closure; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; use function PHPStan\Testing\assertType; enum Status { @@ -43,11 +43,11 @@ function checkFactory(Closure $factory): void { } $default = EnumCollection::of(Status::class); -assertType('Notonza\PhpEnumEx\EnumCase', $default->fromName('Paid')); +assertType('Notonza\PhpEnumEx\Extension\Case\EnumCase', $default->fromName('Paid')); assertType('EnumExStaticAnalysis\Status', $default->fromName('Paid')->unwrap()); $explicit = $default->wrapCasesAs(EnumCase::of(...)); -assertType('Notonza\PhpEnumEx\EnumCase', $explicit->fromName('Paid')); +assertType('Notonza\PhpEnumEx\Extension\Case\EnumCase', $explicit->fromName('Paid')); assertType('EnumExStaticAnalysis\Status', $explicit->fromName('Paid')->unwrap()); $custom = EnumCollection::of(Status::class)->wrapCasesAs(static fn (Status $case) => new LocalizedStatus($case, 'ja')); diff --git a/docs/static-analysis/composite-negative.php b/docs/static-analysis/composite-negative.php index d33bde4..e72833b 100644 --- a/docs/static-analysis/composite-negative.php +++ b/docs/static-analysis/composite-negative.php @@ -4,7 +4,7 @@ namespace EnumExStaticAnalysisCompositeNegative; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; enum Status { case Paid; diff --git a/docs/static-analysis/composite-positive.php b/docs/static-analysis/composite-positive.php index cb08f4b..c3debd7 100644 --- a/docs/static-analysis/composite-positive.php +++ b/docs/static-analysis/composite-positive.php @@ -4,9 +4,9 @@ namespace EnumExStaticAnalysisComposite; -use Notonza\PhpEnumEx\CompositeDuplicates; -use Notonza\PhpEnumEx\CompositeOrder; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates; +use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; use function PHPStan\Testing\assertType; enum Status { @@ -36,16 +36,16 @@ public function __construct( $builder = EnumComposite::as(CompositeOrder::Insensitive); $custom = new Policy(Status::Paid, Role::Admin); -assertType('Notonza\PhpEnumEx\EnumComposite', $standard); -assertType('Notonza\PhpEnumEx\EnumCompositeBuilder', $builder); -assertType('Notonza\PhpEnumEx\EnumComposite', $builder->of(Status::Paid, Role::Admin)); -assertType('Notonza\PhpEnumEx\EnumComposite', Policy::of(Status::Paid, Role::Admin)); -assertType('Notonza\PhpEnumEx\EnumComposite', Policy::as()->of(Status::Paid, Role::Admin)); +assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', $standard); +assertType('Notonza\PhpEnumEx\Extension\Composite\EnumCompositeBuilder', $builder); +assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', $builder->of(Status::Paid, Role::Admin)); +assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', Policy::of(Status::Paid, Role::Admin)); +assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', Policy::as()->of(Status::Paid, Role::Admin)); assertType('list', $standard->unwrap()); assertType('UnitEnum', $standard->at(0)); assertType('ArrayIterator', $standard->getIterator()); -assertType('Notonza\PhpEnumEx\CompositeOrder', $standard->order()); +assertType('Notonza\PhpEnumEx\Extension\Composite\CompositeOrder', $standard->order()); foreach ($standard as $index => $case) { assertType('int', $index); diff --git a/examples/NativeExtension/Backed/ByteUnit.php b/examples/NativeExtension/Backed/ByteUnit.php index 316e2d3..b74d221 100644 --- a/examples/NativeExtension/Backed/ByteUnit.php +++ b/examples/NativeExtension/Backed/ByteUnit.php @@ -6,8 +6,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum ByteUnit: int { case BYTE = 1; diff --git a/examples/NativeExtension/Backed/Currency.php b/examples/NativeExtension/Backed/Currency.php index 91dfaba..7487e8d 100644 --- a/examples/NativeExtension/Backed/Currency.php +++ b/examples/NativeExtension/Backed/Currency.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; enum Currency: string { case JPY = 'JPY'; diff --git a/examples/NativeExtension/Collections/FilePermission.php b/examples/NativeExtension/Collections/FilePermission.php index 6cb38cd..acb17e5 100644 --- a/examples/NativeExtension/Collections/FilePermission.php +++ b/examples/NativeExtension/Collections/FilePermission.php @@ -6,8 +6,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum NoPermission { } diff --git a/examples/NativeExtension/Composite/ConstructionPolicies.php b/examples/NativeExtension/Composite/ConstructionPolicies.php index c8052b1..d778a4e 100644 --- a/examples/NativeExtension/Composite/ConstructionPolicies.php +++ b/examples/NativeExtension/Composite/ConstructionPolicies.php @@ -8,9 +8,9 @@ use InvalidArgumentException; use LogicException; -use Notonza\PhpEnumEx\CompositeDuplicates; -use Notonza\PhpEnumEx\CompositeOrder; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates; +use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; enum WorkflowStep { case Prepare; diff --git a/examples/NativeExtension/Composite/EnumComposite.php b/examples/NativeExtension/Composite/EnumComposite.php index d733f5e..b1edcaa 100644 --- a/examples/NativeExtension/Composite/EnumComposite.php +++ b/examples/NativeExtension/Composite/EnumComposite.php @@ -7,9 +7,9 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; use InvalidArgumentException; -use Notonza\PhpEnumEx\CompositeDuplicates; -use Notonza\PhpEnumEx\CompositeOrder; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates; +use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; enum Country { case Japan; diff --git a/examples/NativeExtension/Composition/OrderStatusBadge.php b/examples/NativeExtension/Composition/OrderStatusBadge.php index c437c3f..b94c034 100644 --- a/examples/NativeExtension/Composition/OrderStatusBadge.php +++ b/examples/NativeExtension/Composition/OrderStatusBadge.php @@ -8,7 +8,7 @@ use Examples\NativeExtension\Presentation\OrderStatus; use Examples\NativeExtension\Presentation\OrderStatusPresentation; -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; /** @extends EnumCase */ final readonly class OrderStatusBadge extends EnumCase { diff --git a/examples/NativeExtension/External/PaymentStatus.php b/examples/NativeExtension/External/PaymentStatus.php index 39ea6e9..9dddf17 100644 --- a/examples/NativeExtension/External/PaymentStatus.php +++ b/examples/NativeExtension/External/PaymentStatus.php @@ -18,7 +18,7 @@ enum PaymentStatus: string { require_once __DIR__ . '/../../../vendor/autoload.php'; use Examples\NativeExtension\External\Vendor\PaymentStatus; - use Notonza\PhpEnumEx\EnumCase; + use Notonza\PhpEnumEx\Extension\Case\EnumCase; /** @extends EnumCase */ final readonly class PaymentStatusPolicy extends EnumCase { diff --git a/examples/NativeExtension/Inheritance/Permission.php b/examples/NativeExtension/Inheritance/Permission.php index b0713c4..b093246 100644 --- a/examples/NativeExtension/Inheritance/Permission.php +++ b/examples/NativeExtension/Inheritance/Permission.php @@ -7,7 +7,7 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; use BackedEnum; -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; enum ArticlePermission: int { case Read = 1; diff --git a/examples/NativeExtension/Presentation/OrderStatus.php b/examples/NativeExtension/Presentation/OrderStatus.php index d54b2ce..fcdf83f 100644 --- a/examples/NativeExtension/Presentation/OrderStatus.php +++ b/examples/NativeExtension/Presentation/OrderStatus.php @@ -7,8 +7,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; use DomainException; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum OrderStatus { case Pending; diff --git a/examples/NativeExtension/Strategies/AirmailPostage.php b/examples/NativeExtension/Strategies/AirmailPostage.php index 048eef6..a00da77 100644 --- a/examples/NativeExtension/Strategies/AirmailPostage.php +++ b/examples/NativeExtension/Strategies/AirmailPostage.php @@ -6,8 +6,8 @@ require_once __DIR__ . '/../../../vendor/autoload.php'; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum AirmailWeight: int { case UpTo25Grams = 25; diff --git a/examples/NativeExtension/Strategies/AirmailPostageByEnum.php b/examples/NativeExtension/Strategies/AirmailPostageByEnum.php index 357844e..87e2534 100644 --- a/examples/NativeExtension/Strategies/AirmailPostageByEnum.php +++ b/examples/NativeExtension/Strategies/AirmailPostageByEnum.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/AirmailPostage.php'; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum AirmailRegion { case Asia; diff --git a/examples/NativeExtension/Strategies/AirmailPostageByFactory.php b/examples/NativeExtension/Strategies/AirmailPostageByFactory.php index 2ed47b7..095d027 100644 --- a/examples/NativeExtension/Strategies/AirmailPostageByFactory.php +++ b/examples/NativeExtension/Strategies/AirmailPostageByFactory.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/AirmailPostage.php'; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; final class AirmailRateFactory { diff --git a/examples/NativeExtension/Strategies/AirmailPostageByType.php b/examples/NativeExtension/Strategies/AirmailPostageByType.php index 1552b99..053cc50 100644 --- a/examples/NativeExtension/Strategies/AirmailPostageByType.php +++ b/examples/NativeExtension/Strategies/AirmailPostageByType.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/AirmailPostage.php'; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; final class AirmailRate { diff --git a/src/EnumCase.php b/src/Extension/Case/EnumCase.php similarity index 99% rename from src/EnumCase.php rename to src/Extension/Case/EnumCase.php index d851699..3fe1b41 100644 --- a/src/EnumCase.php +++ b/src/Extension/Case/EnumCase.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Case; use Notonza\PhpEnumEx\Internal\CaseFormatter; use Notonza\PhpEnumEx\Internal\NativeCaseValue; diff --git a/src/EnumCollection.php b/src/Extension/Collection/EnumCollection.php similarity index 99% rename from src/EnumCollection.php rename to src/Extension/Collection/EnumCollection.php index 312dbc1..f09613b 100644 --- a/src/EnumCollection.php +++ b/src/Extension/Collection/EnumCollection.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Collection; use Closure; use Countable; @@ -10,6 +10,7 @@ use InvalidArgumentException; use IteratorAggregate; use LogicException; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; use Notonza\PhpEnumEx\Internal\CaseFormatter; use Notonza\PhpEnumEx\Internal\NativeCasePredicate; use Notonza\PhpEnumEx\Internal\NativeCaseValue; diff --git a/src/CompositeDuplicates.php b/src/Extension/Composite/CompositeDuplicates.php similarity index 79% rename from src/CompositeDuplicates.php rename to src/Extension/Composite/CompositeDuplicates.php index 542abf4..fa79696 100644 --- a/src/CompositeDuplicates.php +++ b/src/Extension/Composite/CompositeDuplicates.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Composite; /** Determines how repeated native cases are handled during construction. */ enum CompositeDuplicates { diff --git a/src/CompositeOrder.php b/src/Extension/Composite/CompositeOrder.php similarity index 78% rename from src/CompositeOrder.php rename to src/Extension/Composite/CompositeOrder.php index d97c63b..ad65337 100644 --- a/src/CompositeOrder.php +++ b/src/Extension/Composite/CompositeOrder.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Composite; /** Determines whether order matters in policy-based composite equality. */ enum CompositeOrder { diff --git a/src/EnumComposite.php b/src/Extension/Composite/EnumComposite.php similarity index 99% rename from src/EnumComposite.php rename to src/Extension/Composite/EnumComposite.php index 1125cd9..79a73c8 100644 --- a/src/EnumComposite.php +++ b/src/Extension/Composite/EnumComposite.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Composite; use ArrayIterator; use Countable; diff --git a/src/EnumCompositeBuilder.php b/src/Extension/Composite/EnumCompositeBuilder.php similarity index 95% rename from src/EnumCompositeBuilder.php rename to src/Extension/Composite/EnumCompositeBuilder.php index 999ccb2..a1fe78d 100644 --- a/src/EnumCompositeBuilder.php +++ b/src/Extension/Composite/EnumCompositeBuilder.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Notonza\PhpEnumEx; +namespace Notonza\PhpEnumEx\Extension\Composite; use Closure; use UnitEnum; diff --git a/src/Internal/NativeCasePredicate.php b/src/Internal/NativeCasePredicate.php index 79e6648..54c7e98 100644 --- a/src/Internal/NativeCasePredicate.php +++ b/src/Internal/NativeCasePredicate.php @@ -4,7 +4,7 @@ namespace Notonza\PhpEnumEx\Internal; -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; use Closure; use Generator; use UnitEnum; diff --git a/tests/NativeCollection/EnumCollectionTest.php b/tests/NativeCollection/EnumCollectionTest.php index 44aa9da..097eff7 100644 --- a/tests/NativeCollection/EnumCollectionTest.php +++ b/tests/NativeCollection/EnumCollectionTest.php @@ -6,8 +6,8 @@ use InvalidArgumentException; use LogicException; -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; use Notonza\PhpEnumEx\EnumTraits\EnumCollections; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; diff --git a/tests/NativeExtension/EnumCaseTest.php b/tests/NativeExtension/EnumCaseTest.php index 01421de..532869c 100644 --- a/tests/NativeExtension/EnumCaseTest.php +++ b/tests/NativeExtension/EnumCaseTest.php @@ -4,7 +4,7 @@ namespace Tests\NativeExtension; -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; diff --git a/tests/NativeExtension/EnumCompositeTest.php b/tests/NativeExtension/EnumCompositeTest.php index 9110695..198d55b 100644 --- a/tests/NativeExtension/EnumCompositeTest.php +++ b/tests/NativeExtension/EnumCompositeTest.php @@ -6,9 +6,9 @@ use InvalidArgumentException; use LogicException; -use Notonza\PhpEnumEx\CompositeDuplicates; -use Notonza\PhpEnumEx\CompositeOrder; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates; +use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; use OutOfBoundsException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; diff --git a/tests/NativeTraits/EnumCollectionsTest.php b/tests/NativeTraits/EnumCollectionsTest.php index 766b4be..8a430fc 100644 --- a/tests/NativeTraits/EnumCollectionsTest.php +++ b/tests/NativeTraits/EnumCollectionsTest.php @@ -254,8 +254,8 @@ public function testPureCollections(): void { $this->assertNull(PureStatus::tryFromValue('paid')); $this->assertTrue(PureStatus::hasValue('Paid')); $this->assertSame('Paid', PureStatus::Paid->value()); - $this->assertSame(['Paid' => PureStatus::Paid], PureStatus::filter([\Notonza\PhpEnumEx\EnumCase::of(PureStatus::Paid)])); - $this->assertSame(['Paid' => PureStatus::Paid], PureStatus::only([\Notonza\PhpEnumEx\EnumCase::of(PureStatus::Paid)])); + $this->assertSame(['Paid' => PureStatus::Paid], PureStatus::filter([\Notonza\PhpEnumEx\Extension\Case\EnumCase::of(PureStatus::Paid)])); + $this->assertSame(['Paid' => PureStatus::Paid], PureStatus::only([\Notonza\PhpEnumEx\Extension\Case\EnumCase::of(PureStatus::Paid)])); } public function testSelectionAndExclusionShareStrictMatching(): void { From 0dbc9959ea317f50028d50aa487450cae63b99f2 Mon Sep 17 00:00:00 2001 From: Kangin Kim Date: Thu, 3 Dec 2026 17:41:13 +0900 Subject: [PATCH 2/3] Document extension namespace migration and architectural decision --- README.md | 70 ++++++++++--------- .../0012-organize-native-enum-extensions.md | 34 +++++++++ docs/adr/README.md | 1 + 3 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 docs/adr/0012-organize-native-enum-extensions.md diff --git a/README.md b/README.md index 57a3276..3edb897 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ Native enum extensions, collections, composites, reusable enum traits, and [clas Keep the original native enum unchanged. Bit shifts define exact powers of two; independent wrappers provide decimal and hexadecimal behavior. The decimal wrapper also exposes the byte count, decimal digit count, and conversion to kilobytes. ```php -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum ByteUnit: int { case BYTE = 1; @@ -118,15 +118,15 @@ $unit->toKilobytes(); // 1048.576 $decimal->fromName('MEBIBYTE')->is($hex->fromName('MEBIBYTE')); // true ``` -See [ByteUnit](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Backed/ByteUnit.php). The decimal grouping and hexadecimal formatting are illustrative. `toKilobytes()` uses decimal kilobytes (1 kB = 1000 bytes), not kibibytes (1 KiB = 1024 bytes). +See [ByteUnit](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Backed/ByteUnit.php). The decimal grouping and hexadecimal formatting are illustrative. `toKilobytes()` uses decimal kilobytes (1 kB = 1000 bytes), not kibibytes (1 KiB = 1024 bytes). ### File permissions: same enum, different context A bit flag occupies one bit. Combine flags into an integer mask and give each wrapper the mask for its context, without changing the original enum. ```php -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum FilePermission: int { case READ = 1 << 0; @@ -189,7 +189,7 @@ $checks->fromName('WRITE')->is($guest->fromName('WRITE')); // true The original native case remains the same, even when different masks produce different results. The mask is an integer, not an enum case; unknown bits do not create cases. This is an illustrative bit-flag example, not a complete authorization policy. -See [FilePermission](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Collections/FilePermission.php), the [trait variant](#working-with-bit-flags) and the [class-based inheritance variant](README-ClassBased.md#extend-bit-flags-through-inheritance). +See [FilePermission](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Collections/FilePermission.php), the [trait variant](#working-with-bit-flags) and the [class-based inheritance variant](README-ClassBased.md#extend-bit-flags-through-inheritance). ## Requirements and installation @@ -197,7 +197,7 @@ The Composer package is `notonza/php-enumex` (formerly `gachakra/php-enum`). Its The library requires PHP `^8.4`. Development and testing require PHP 8.4.1 or later within that range because of the PHPUnit version in `composer.lock`. -This README describes the development API for the next major release. The native mapping and qualified-formatting names below replace v2 names and are not available in the released v2 package. For the stable v2 API, use the README at the installed release tag: +This README describes the development API for the next major release. The native extension namespaces and the mapping and qualified-formatting APIs below differ from those in the released v2 package. For the stable v2 API, use the README at the installed release tag: ```bash composer require notonza/php-enumex:^2.0 @@ -214,12 +214,16 @@ The public APIs are organized by approach: | Namespace | Purpose | | --- | --- | -| `Notonza\PhpEnumEx` | `EnumCase`, `EnumCollection`, and `EnumComposite` | +| `Notonza\PhpEnumEx\Extension\Case` | `EnumCase` | +| `Notonza\PhpEnumEx\Extension\Collection` | `EnumCollection` | +| `Notonza\PhpEnumEx\Extension\Composite` | `EnumComposite`, `EnumCompositeBuilder`, `CompositeOrder`, and `CompositeDuplicates` | | `Notonza\PhpEnumEx\EnumTraits` | `EnumMethods` and `EnumCollections` | | `Notonza\PhpEnumEx\ClassBased` | Original class-based Enum and its exceptions | The `Internal` namespace is not a public API. +**Migration from v2:** update imports of native extension classes formerly in the root namespace to their corresponding `Extension\Case`, `Extension\Collection`, or `Extension\Composite` namespace above. Update fully qualified type references, PHPDoc, and configuration containing class names as well. The class names, PSR-4 root, EnumTraits and ClassBased namespaces remain unchanged. No legacy namespace aliases are provided. If an application persists PHP objects or class names containing the old namespaces, handle that migration explicitly. + ## Choosing an approach | Approach | When to use it | @@ -238,7 +242,7 @@ EnumEx lets you work with both pure enums (`UnitEnum` only) and backed enums (`B For example, given a pure Direction enum with North and a string-backed Currency enum with JPY = 'JPY': ```php -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; EnumCase::of(Direction::North)->value(); // 'North' (UnitEnum only) EnumCase::of(Currency::JPY)->value(); // 'JPY' (BackedEnum) @@ -257,8 +261,8 @@ Keep presentation concerns out of the domain layer. An order status is a domain The wrapper can also carry context such as a locale, which native enum cases cannot store as instance properties. The same enum can have separate wrappers for UI labels, colors, or other contexts without accumulating unrelated methods in its definition. ```php -use Notonza\PhpEnumEx\EnumCase; -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; enum OrderStatus { case Pending; @@ -320,14 +324,14 @@ $japanese->fromName('Paid')->is( $statuses->fromValue('Paid')->value(); // 'Paid' ``` -See [Presentation / OrderStatus](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Presentation/OrderStatus.php). +See [Presentation / OrderStatus](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Presentation/OrderStatus.php). #### Formatting monetary amounts Currency formatting is another presentation concern. A string-backed currency enum can retain its logical value while a wrapper supplies a display convention. ```php -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; enum Currency: string { case JPY = 'JPY'; @@ -374,7 +378,7 @@ CurrencyFormatter::from(Currency::EUR)->format(1234.5); // '€1,234.50' The formatter applies the currency's usual number of decimal places with a fixed display convention. Digit grouping is enabled by default and can be disabled with `grouping: false`. It is not locale-aware and does not perform currency conversion. -See [Backed / Currency](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Backed/Currency.php). +See [Backed / Currency](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Backed/Currency.php). The [byte unit example](#byte-units-same-enum-different-formatting) above uses the same extension mechanism with integer backing values. @@ -383,7 +387,7 @@ The [byte unit example](#byte-units-same-enum-different-formatting) above uses t Suppose a vendor SDK exposes a `PaymentStatus` enum. Application-specific policies can be added without modifying the SDK or wrapping its values in a second enum definition. ```php -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; use Examples\NativeExtension\External\Vendor\PaymentStatus; /** @extends EnumCase */ @@ -406,14 +410,14 @@ $policy->requiresNotification(); // true $policy->unwrap() === PaymentStatus::Failed; // true ``` -The example simulates a vendor SDK; replace the imported enum with the actual vendor type in an application. See [External / PaymentStatus](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/External/PaymentStatus.php). +The example simulates a vendor SDK; replace the imported enum with the actual vendor type in an application. See [External / PaymentStatus](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/External/PaymentStatus.php). ### 3. Share and specialize behavior through inheritance Native enums cannot inherit from other enums or classes. Extension classes can share implementation through an abstract parent and specialize it for distinct enum types. ```php -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; /** * @template TCase of BackedEnum @@ -436,14 +440,14 @@ ArticleAccess::from(ArticlePermission::Write)->canPublish(); // false UserAccess::from(UserPermission::Admin)->canDeleteUser(); // true ``` -See [Inheritance / Permission](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Inheritance/Permission.php). +See [Inheritance / Permission](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Inheritance/Permission.php). ### 4. Strategy: vary behavior without changing the enum Use a single native enum for weight categories and choose a strategy according to the destination. Each strategy receives the same type of enum case but supplies a different implementation. This example fixes the strategy constructor so the inherited factory can safely instantiate every subclass. If strategies require different constructor arguments, define factories in their concrete classes instead. ```php -use Notonza\PhpEnumEx\EnumCase; +use Notonza\PhpEnumEx\Extension\Case\EnumCase; enum AirmailWeight: int { case UpTo25Grams = 25; @@ -501,7 +505,7 @@ calculatePostage(EuropeAirmailRate::from($weight)); // 110 Use the same strategies across a collection: ```php -use Notonza\PhpEnumEx\EnumCollection; +use Notonza\PhpEnumEx\Extension\Collection\EnumCollection; $weights = EnumCollection::of(AirmailWeight::class); @@ -520,9 +524,9 @@ array_keys($europe->filter($affordable)); // [] The concrete strategies above are selected explicitly for illustration. In an application, configuration or runtime context can determine the strategy through a factory, a resolver, or a dependency injection container. The collection does not need to know how that choice was made. -For example, an application-defined resolver can return a factory, a strategy class, or a native enum case. The following are independent usage examples based on the linked implementation. The resolver implementations are omitted here; each approach has its own executable example linked below. They share the enum, strategies and business function from [AirmailPostage.php](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Strategies/AirmailPostage.php). +For example, an application-defined resolver can return a factory, a strategy class, or a native enum case. The following are independent usage examples based on the linked implementation. The resolver implementations are omitted here; each approach has its own executable example linked below. They share the enum, strategies and business function from [AirmailPostage.php](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Strategies/AirmailPostage.php). -Resolve a factory (a typed Closure) and pass it directly to the collection ([AirmailPostageByFactory.php](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Strategies/AirmailPostageByFactory.php)): +Resolve a factory (a typed Closure) and pass it directly to the collection ([AirmailPostageByFactory.php](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Strategies/AirmailPostageByFactory.php)): ```php $destination = 'asia'; // Selected by application configuration or runtime context. @@ -535,7 +539,7 @@ $rates = EnumCollection::of(AirmailWeight::class) calculatePostage($rates->fromValue(25)); // 90 (for $destination = 'asia') ``` -Alternatively, resolve a strategy type (a class-string) and turn its factory method into a Closure ([AirmailPostageByType.php](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Strategies/AirmailPostageByType.php)): +Alternatively, resolve a strategy type (a class-string) and turn its factory method into a Closure ([AirmailPostageByType.php](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Strategies/AirmailPostageByType.php)): ```php $rateType = AirmailRate::resolve($destination); // returns class-string @@ -546,7 +550,7 @@ $rates = EnumCollection::of(AirmailWeight::class) calculatePostage($rates->fromValue(25)); // 90 (for $destination = 'asia') ``` -Or resolve a native enum case that provides a strategy factory method ([AirmailPostageByEnum.php](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Strategies/AirmailPostageByEnum.php)): +Or resolve a native enum case that provides a strategy factory method ([AirmailPostageByEnum.php](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Strategies/AirmailPostageByEnum.php)): ```php $region = AirmailRegion::resolve($destination); // returns enum @@ -559,7 +563,7 @@ calculatePostage($rates->fromValue(25)); // 90 (for $destination = 'asia') All three approaches separate strategy selection from business logic. A factory can also capture additional configuration or dependencies when constructing wrappers. The enum-based approach lets one native enum determine the behavior of another. `AirmailRateFactory`, `AirmailRate` and `AirmailRegion` are application-defined examples, not EnumEx APIs. -The original enum remains unchanged. New strategies can be added without modifying its definition or existing strategies. The rates are illustrative, not current postal rates. The complete example also includes an Africa strategy. See [Strategies / AirmailPostage](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Strategies/AirmailPostage.php). +The original enum remains unchanged. New strategies can be added without modifying its definition or existing strategies. The rates are illustrative, not current postal rates. The complete example also includes an Africa strategy. See [Strategies / AirmailPostage](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Strategies/AirmailPostage.php). ### 5. Reuse and combine existing behaviors @@ -653,7 +657,7 @@ The badge retains the presentation object, delegates its localized label and sup Rewrapping a case through unwrap() alone does not retain the previous wrapper. Use explicit composition when the existing extension's state or behavior must remain available. -See [Composition / OrderStatusBadge](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Composition/OrderStatusBadge.php) for the runnable example, including additional statuses and locale checks. +See [Composition / OrderStatusBadge](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Composition/OrderStatusBadge.php) for the runnable example, including additional statuses and locale checks. This combines behaviors around one native case. [Native Enum Composites](#native-enum-composites), in contrast, represent multiple native cases as a single structured value. @@ -766,9 +770,9 @@ The same selection operations are available as static methods on the native coll A travel route needs both the order and the repeated occurrence of a country: ```php -use Notonza\PhpEnumEx\CompositeDuplicates; -use Notonza\PhpEnumEx\CompositeOrder; -use Notonza\PhpEnumEx\EnumComposite; +use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates; +use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder; +use Notonza\PhpEnumEx\Extension\Composite\EnumComposite; enum Country { case Japan; @@ -826,7 +830,7 @@ When merging requirements, a repeated verification is needed only once, and the | Sensitive | Sequence | Ordered unique sequence | Ordered unique sequence (validated) | | Insensitive | Multiset | Set | Set (validated) | -For more policy examples, see [Composite / ConstructionPolicies](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Composite/ConstructionPolicies.php): merge or validate an ordered workflow, compare package contents including quantities, and validate an unordered set of notification channels. Together with the examples above, these cover all six construction-policy combinations. +For more policy examples, see [Composite / ConstructionPolicies](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Composite/ConstructionPolicies.php): merge or validate an ordered workflow, compare package contents including quantities, and validate an unordered set of notification channels. Together with the examples above, these cover all six construction-policy combinations. ### Structural equality @@ -895,7 +899,7 @@ final readonly class OrderStatusPolicy extends EnumComposite { Use the typed properties when the roles matter. The composite's structural comparison and membership operations remain available, and both status and role participate in equality. The standard of() and as()->of() factories always create a standard EnumComposite, not a subclass. -See [EnumComposite](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeExtension/Composite/EnumComposite.php) for runnable examples, including typed subclasses, dynamic requirements and duplicate rejection. +See [EnumComposite](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeExtension/Composite/EnumComposite.php) for runnable examples, including typed subclasses, dynamic requirements and duplicate rejection. ## Native Enum Traits @@ -989,7 +993,7 @@ array_keys(FilePermission::denied($mask)); // ['EXECUTE'] The mask is an integer, not an enum case. The collections contain the declared cases only, and unknown bits do not produce additional cases. This is a simplified bit-flag example, not a complete authorization policy. -See [Collections / FilePermission](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeTraits/Collections/FilePermission.php) and the [class-based inheritance variant](README-ClassBased.md#extend-bit-flags-through-inheritance). +See [Collections / FilePermission](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeTraits/Collections/FilePermission.php) and the [class-based inheritance variant](README-ClassBased.md#extend-bit-flags-through-inheritance). ### Combine library traits with your own traits @@ -1010,7 +1014,7 @@ ShipmentStatus::joinValues(); // ',0,1,2' ShipmentStatus::joinValues(';', skipEmpty: true); // '0;1;2' ``` -`JoinsEnumValues` is an example of an application-defined trait, not a library API. It builds on `values()` and optionally excludes empty strings while preserving valid values such as `'0'`. See [UseTrait / JoinsEnumValues](https://github.com/gachakra/php-enumex/blob/f00f7ac3412789ba8ce179fb449be4a3cb43b4c0/examples/NativeTraits/UseTrait/JoinsEnumValues.php). +`JoinsEnumValues` is an example of an application-defined trait, not a library API. It builds on `values()` and optionally excludes empty strings while preserving valid values such as `'0'`. See [UseTrait / JoinsEnumValues](https://github.com/gachakra/php-enumex/blob/21843ce4cc3856c09260422236763ce2a54c3fc8/examples/NativeTraits/UseTrait/JoinsEnumValues.php). ## Running the native enum examples diff --git a/docs/adr/0012-organize-native-enum-extensions.md b/docs/adr/0012-organize-native-enum-extensions.md new file mode 100644 index 0000000..2ff2175 --- /dev/null +++ b/docs/adr/0012-organize-native-enum-extensions.md @@ -0,0 +1,34 @@ +# ADR 0012: Organize native enum extensions by concept + +- Status: Accepted (for the next major development cycle; release version remains a separate decision) +- Date: 2026-12-03 +- Related: ADR 0001, 0002, 0006, 0008, 0010, 0011 + +## Context + +Native enum extension classes currently share the root package namespace. EnumCase, EnumCollection and EnumComposite are distinct concepts, but all extend native enum behavior through composition. Class-based Enum is a separate abstraction with its own historical contract; native enum traits add methods directly to enums. Composite already includes policy types and a builder. Collection may later gain a lazy view (ADR 0008). Organizing the API solely by current file count risks repeated namespace changes as these concepts evolve. + +## Decision + +Use `Notonza\PhpEnumEx\Extension` for external extensions of native enums, with concept-specific namespaces: + +| Namespace relative to package root | Types | +| --- | --- | +| Extension\Case | EnumCase | +| Extension\Collection | EnumCollection | +| Extension\Composite | EnumComposite, EnumCompositeBuilder, CompositeOrder, CompositeDuplicates | + +Mirror these namespaces under src/ using the existing PSR-4 mapping. Retain EnumTraits, ClassBased (including Exceptions), and Internal at their existing locations. Internal is for shared implementation details, not a public extension API. Keep class names and method contracts unchanged. Class-based nameToElement() remains supported. + +A namespace may contain only one class: conceptual independence, not file count, determines its boundary. Add new concept namespaces when concrete needs justify them; do not pre-create empty directories or introduce speculative abstractions. A lazy collection view, specialized composite contracts, flags or enum-keyed maps are possible directions, not accepted features or API commitments. + +## Alternatives + +- Keep root-level types: concise imports, but weak grouping as extension concepts acquire related types. +- Move only composite support types: preserves short imports for principal types but separates the composite from its own policies and builder. +- Use Case, Collection and Composite directly under the package root: expresses concept boundaries but not their shared role as native enum extensions distinct from ClassBased and EnumTraits. +- Place Composite beside Extension: rejected because composite is itself a native enum extension. + +## Consequences + +Imports, fully qualified references, documentation, test fixtures and static-analysis paths must follow the new namespaces. This is a breaking namespace change intended for the next major release. Do not add compatibility aliases without a separate decision; v2 remains available at its release tag. Persisted class names and serialized objects referencing the old names may require application-level migration. Historical ADRs retain their original context and names; this record supersedes their previous namespace placement where applicable. The new structure does not change runtime semantics or establish any new collection or composite feature. diff --git a/docs/adr/README.md b/docs/adr/README.md index 4b83989..8c5fad8 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -15,5 +15,6 @@ These records capture the motivation and decisions behind PHP EnumEx, including | [0009](0009-documentation-and-extension-composition.md) | Explain common enum behavior and composition through useful examples | Proposed | | [0010](0010-composite-enum-cases.md) | Explore a composite of native enum cases | Proposed | | [0011](0011-mapping-and-qualified-formatting.md) | Explicit mapping and qualified formatting APIs | Proposed | +| [0012](0012-organize-native-enum-extensions.md) | Organize native enum extensions by concept | Accepted | Accepted means the architectural direction has been agreed. Open implementation details are identified separately and must not be treated as finalized API contracts. Amend or supersede these records when decisions change. From ea236f6832662d5138177896160b3132ead9d474 Mon Sep 17 00:00:00 2001 From: Kangin Kim Date: Thu, 3 Dec 2026 17:41:30 +0900 Subject: [PATCH 3/3] Delegate development resource names to Compose while retaining a single image build --- README.md | 4 +++- docker-compose.yml | 16 ++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3edb897..fdee164 100644 --- a/README.md +++ b/README.md @@ -1043,6 +1043,8 @@ php -d zend.assertions=1 examples/NativeTraits/UseTrait/JoinsEnumValues.php From a Git checkout (not the installed Composer package): +If migrating an existing development environment, run `docker compose down --remove-orphans` with the previous Compose configuration and project name before switching to this configuration. This removes the old fixed-name containers and custom network without deleting `vendor/` or the named cache volume. If the project name changes, the old cache remains in its original project-scoped volume. + ```bash docker compose up -d --build --remove-orphans docker compose ps -a @@ -1050,7 +1052,7 @@ docker compose ps -a Docker is a CLI-only development environment; no HTTP service or host port is published. The `--remove-orphans` option also removes the obsolete Nginx service if you used an older checkout. -Both services use the same PHP 8.4 CLI image and mount the project directory. Only the `composer` service builds the shared local image; the `php` service uses that image without pulling it. To build the image explicitly, run `docker compose build composer`. +The default Compose project name is `php-enumex`. Compose manages container names and the default project network automatically. Both services use the same PHP 8.4 CLI image, tagged `${COMPOSE_PROJECT_NAME}:local`, and mount the project directory. Use `docker compose -p ` consistently to isolate Compose resources for another checkout; separate checkouts also keep their bind-mounted `vendor/` directories separate. Only the `composer` service builds the shared local image; the `php` service uses that image without pulling it. To build the image explicitly, run `docker compose build composer`. The one-shot `composer` service installs the locked development dependencies into the host project's `vendor/` directory, then exits. On a fresh startup with `docker compose up`, the `php` service waits for Composer to exit successfully and then remains available for development. The host IDE and both services see the same installed dependencies. The named `composer-cache` volume retains downloaded package data independently of the installed dependencies. diff --git a/docker-compose.yml b/docker-compose.yml index cffbdb2..07b585e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ +name: php-enumex + services: php: - image: php-enumex:local + image: ${COMPOSE_PROJECT_NAME}:local pull_policy: never - container_name: php-enumex_php volumes: - .:/var/www/php-enumex working_dir: /var/www/php-enumex @@ -14,16 +15,13 @@ services: - -c - | exec tail -f /dev/null - networks: - - php-enumex composer: - image: php-enumex:local + image: ${COMPOSE_PROJECT_NAME}:local build: context: ./docker/php args: TIMEZONE: Asia/Tokyo - container_name: php-enumex_composer environment: COMPOSER_CACHE_DIR: /root/.cache/composer volumes: @@ -35,12 +33,6 @@ services: - -c - | exec composer install --optimize-autoloader --no-interaction - networks: - - php-enumex volumes: composer-cache: - -networks: - php-enumex: - name: php-enumex