Created
April 6, 2026 05:39
-
-
Save edgrosvenor/c00971fd454eebe6d36a73a145f2e12d to your computer and use it in GitHub Desktop.
Fat Enums: State machine definition with transition attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Enums; | |
| use ArtisanBuild\FatEnums\Attributes\CanTransitionTo; | |
| use ArtisanBuild\FatEnums\Attributes\CanTransitionToSelf; | |
| use ArtisanBuild\FatEnums\Attributes\FinalState; | |
| use ArtisanBuild\FatEnums\Concerns\IsStateMachine; | |
| use ArtisanBuild\FatEnums\Contracts\StateMachine; | |
| enum OrderStatus: string implements StateMachine | |
| { | |
| use IsStateMachine; | |
| public const DEFAULT = self::Pending; | |
| #[CanTransitionTo([self::Processing, self::Cancelled])] | |
| case Pending = 'pending'; | |
| #[CanTransitionTo([self::Shipped, self::Cancelled])] | |
| #[CanTransitionToSelf] // Can re-process if needed | |
| case Processing = 'processing'; | |
| #[CanTransitionTo([self::Delivered, self::Returned])] | |
| case Shipped = 'shipped'; | |
| #[FinalState] | |
| case Delivered = 'delivered'; | |
| #[FinalState] | |
| case Cancelled = 'cancelled'; | |
| #[CanTransitionTo([self::Refunded])] | |
| case Returned = 'returned'; | |
| #[FinalState] | |
| case Refunded = 'refunded'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment