{"id":22963645,"url":"https://github.com/half0wl/php-statemachine","last_synced_at":"2025-07-19T05:07:25.921Z","repository":{"id":142640643,"uuid":"420501697","full_name":"half0wl/php-StateMachine","owner":"half0wl","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-14T17:09:05.000Z","size":45,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T03:46:00.224Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/half0wl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-23T19:14:24.000Z","updated_at":"2023-03-14T17:10:01.000Z","dependencies_parsed_at":"2023-04-07T10:09:05.000Z","dependency_job_id":null,"html_url":"https://github.com/half0wl/php-StateMachine","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/half0wl/php-StateMachine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fphp-StateMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fphp-StateMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fphp-StateMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fphp-StateMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/half0wl","download_url":"https://codeload.github.com/half0wl/php-StateMachine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/half0wl%2Fphp-StateMachine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265892108,"owners_count":23844968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T19:37:07.053Z","updated_at":"2025-07-19T05:07:25.890Z","avatar_url":"https://github.com/half0wl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-StateMachine\n\n[![Latest Stable Version](http://poser.pugx.org/halfowl/statemachine/v)](https://packagist.org/packages/halfowl/statemachine) [![Total Downloads](http://poser.pugx.org/halfowl/statemachine/downloads)](https://packagist.org/packages/halfowl/statemachine) [![License](http://poser.pugx.org/halfowl/statemachine/license)](https://packagist.org/packages/halfowl/statemachine) [![PHP Version Require](http://poser.pugx.org/halfowl/statemachine/require/php)](https://packagist.org/packages/halfowl/statemachine)\n\nState Machines in PHP made safe and easy.\n\n## Installation\n\nUsing Composer:\n```\n$ composer require halfowl/statemachine\n```\n\n## Example\n\nImagine an application that holds the state of an article. It has the\nfollowing states:\n\n- Draft\n- Awaiting Copy Edit\n- Published\n\nA new article starts in \"Draft\", gets progressed to \"Awaiting Copy Edit\",\nand subsequently \"Published\". An article in \"Awaiting Copy Edit\" can go\nback to being a \"Draft\".\n\nWith this library, you can model the above as:\n\n```php\n\u003c?php\n\nuse Halfowl\\StateMachine\\{State, StateMachine, StateTransition};\n\n$draft = new State(\"DRAFT\");\n$awaitingCopy = new State(\"AWAITING_COPY_EDIT\");\n$published = new State(\"PUBLISHED\");\n\n// StateTransitions define legal state transitions for the StateMachine.\n// The second parameter of the constructor takes in an array of States\n// that the first State can transition to.\n$fromDraft = new StateTransition($draft, [$awaitingCopy]);  // draft-\u003eawaiting copy\n$fromAwaitingCopy = new StateTransition($awaitingCopy, [$draft, $published]);  // awaiting copy-\u003edraft/published\n\n// Put that together into a StateMachine:\n$sm = new StateMachine(\n    transitions: [\n        $fromDraft,\n        $fromAwaitingCopy,\n    ],\n    starting: $draft,\n);\n\n$sm-\u003ecurrent();                  // =\u003e DRAFT\n$sm-\u003etransition($awaitingCopy);  // =\u003e AWAITING_COPY_EDIT\n$sm-\u003etransition($published);     // =\u003e PUBLISHED\n```\n\n## API\n\n(Proper auto-generated docs is WIP, tracking in #4)\n\n### State\n\nReference: https://github.com/half0wl/php-StateMachine/blob/main/src/StateInterface.php\n\n* `getName(): string`\n\n### StateMachine\n\nReference: https://github.com/half0wl/php-StateMachine/blob/main/src/StateMachineInterface.php\n\n* `current(): State`\n* `can(): bool`\n* `is(State $s): bool`\n* `transition(State $next): void`\n\n### StateTransition\n\nReference: https://github.com/half0wl/php-StateMachine/blob/main/src/StateTransitionInterface.php\n\n* `src(): State`\n* `dsts(): State[]`\n* `inDst(): bool`\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalf0wl%2Fphp-statemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalf0wl%2Fphp-statemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalf0wl%2Fphp-statemachine/lists"}