tarfin-labs / event-machine
An event-driven state machine library for PHP, providing an expressive language to define and manage application states, enabling developers to create complex workflows with ease and maintainability.
Installs: 4 484
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 7
Forks: 1
Open Issues: 0
Requires
- php: ^8.2|^8.3
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-data: ^3.3
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- infection/infection: ^0.29.6
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.4
- pestphp/pest-plugin-type-coverage: ^2.8
- dev-main
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-setting-machines-in-model-method
- dev-WB-338-event-machine-fix-type-checking-behavior-on-behavior-dependency-injection
- dev-WB-291-event-machine-update-machine-cast-set-method-to-handle-uninitialized-machines
- dev-laravel-11-upgrade
- dev-WEB-5096-event-machine-state-machine-diagramlarini-otomatik-olusturabilmek
- dev-WEB-5120-form-request-siniflarinda-bail-ifadesinin-kaldirilmasi-ve-stop-on-first-failure-ozelliginin-kullanilmasi
- dev-WEB-4823-event-machine-mockable-actions
- dev-WEB-4724-basvuru-makinesi-disindaki-makinelerin-loglari-kapatilabilir
- dev-WEB-4689-replace-deprecated-package-nunomaduro-larastan-with-larastan-larastan
- dev-WEB-4344-event-machine-behavior-dependency-injection
- dev-WEB-4286-event-machine-json-alanlarinin-boyutunu-azaltmak
- dev-WEB-4311-event-machine-guardlarin-start-eventlerini-artik-kaydetmeyelim
- dev-WEB-4061-test-senaryo-datalarinin-v-4-te-kullanilabilir-olmasinin-saglanmasi
- dev-WEB-4267-event-machine-makine-calisiyor-yeni-event-kabul-etmeye-hazir-durumlari
- dev-WEB-3989-event-machine-transactional-transition-tanimlanmasi
- dev-WEB-4240-event-machine-actions-and-guards-that-log-itself
- dev-WEB-4287-event-machine-auto-castingi-engellemek
- dev-WEB-3988-event-machine-performer-tanimlanmasi
- dev-WEB-3991-event-machine-introduce-top-level-transitions
- dev-WEB-3993-event-machine-full-path-on-internal-event-types
- dev-WEB-3985-event-machine-introduce-machine-results
- dev-WEB-3980-event-machine-capture-events-from-child-states-and-forbidden-transitions
- dev-WEB-3973-event-machine-enable-validation-guards-in-guarded-transitions
- dev-WEB-3936-event-machine-initialize-custom-context-manager-from-machine-config
- dev-WEB-3924-event-machine-do-not-throw-validation-errors-for-the-past-events-in-the-history
- dev-WEB-3929-event-machine-do-not-throw-validation-errors
- dev-WEB-3913-event-machine-class-type-control-issue-in-get-set-and-has-methods-in-context-manager
- dev-WEB-3905-event-machine-use-logic-exceptions-instead-of-runtime-exceptions
- dev-WEB-3908-event-machine-improve-event-name-generation-from-class-names
- dev-WEB-3907-event-machine-internal-raised-event-bug
- dev-WEB-3900-event-machine-improved-internal-events
- dev-WEB-3904-event-machine-introduce-final-states
- dev-WEB-3903-event-machine-prevent-validation-guards-inside-guarded-transitions
- dev-WEB-3902-event-machine-fix-generating-state-init-event-on-initial-state
- dev-WEB-3901-event-machine-rename-internal-events-using-machine-id
- dev-WEB-3893-event-machine-introducing-validation-guards
- dev-WEB-3891-event-machine-first-guard-error-returns-instead-of-last
- dev-WEB-3874-event-machine-validate-invokable-behavior-through-itself
- dev-WEB-3873-event-machine-dont-validate-factory-created-events-immediately
- dev-WEB-3872-event-machine-validate-events
- dev-WEB-3866-event-machine-introduce-required-context-for-actions
- dev-WEB-3864-event-machine-introduce-no-transition-found-exception
- dev-WEB-3851-event-machine-introduce-required-context-definitions
- dev-WEB-3846-event-machine-casting-machine-actor-to-string
- dev-WEB-3843-event-machine-save-raised-events-to-history
- dev-WEB-3842-event-machine-save-state-init-internal-event
- dev-WEB-3841-event-machine-handle-json-serialization-of-the-machine-actor
- dev-WEB-3840-event-machine-entry-actions-are-saved-in-wrong-state-in-machine-events-table
- dev-WEB-3839-event-machine-sub-state-transition-error
- dev-WEB-3837-event-machine-entry-actions-of-states-with-sub-states-do-not-work
- dev-WEB-3825-event-machine-ability-to-raise-events-and-introduce-internal-event-queue
- dev-WEB-3824-event-machine-matching-state-values
- dev-WEB-3823-event-machine-actions-that-returns
- dev-WEB-3816-event-machine-introduce-transition-branch-definitions
- dev-WEB-3815-event-machine-introduce-invokable-behavior-arguments
- dev-WEB-3803-event-machine-introduce-type-check-for-context-manager
- dev-WEB-3802-event-machine-introduce-magic-methods-for-context-manager
- dev-WEB-3786-event-machine-introduce-event-factory-to-generate-fake-events-using-laravels-factory-mechanism
- dev-WEB-3782-throwing-validation-guards-with-error-messages
- dev-WEB-3781-content-manager-handle-context-manager-subclasses
- dev-WEB-3770-access-laravel-models-through-the-machines
- dev-WEB-3768-cast-model-attributes-as-event-machines
- dev-WEB-3760-persisting-machine-state
- dev-WEB-3761-record-internal-event-types-as-base-class-names-instead-of-fqcn
- dev-WEB-3748-propagate-event-and-state-definition-information-through-state
- dev-WEB-3747-fix-machine-actor-update-send-method-to-assign-the-new-state
- dev-WEB-3703-introduce-internal-events
- dev-WEB-3702-introduce-event-store
- dev-WEB-3701-update-event-behavior-constructor-with-optional-version-parameter
- dev-WEB-3699-add-version-property-to-event-behavior
- dev-initial-state-entry-action-fix
This package is auto-updated.
Last update: 2024-09-04 13:56:18 UTC
README
EventMachine is a PHP library for creating and managing event-driven state machines. It is designed to be simple and easy to use, while providing powerful functionality for managing complex state transitions. This library is heavily influenced by XState, a popular JavaScript state machine library.
Installation
You can install the package via composer:
composer require tarfin-labs/event-machine
You can publish and run the migrations with:
php artisan vendor:publish --tag="event-machine-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="event-machine-config"
This is the contents of the published config file:
return [
];
Usage
$machine = MachineDefinition::define( config: [ 'initial' => 'green', 'context' => [ 'value' => 1, ], 'states' => [ 'green' => [ 'on' => [ 'TIMER' => [ [ 'target' => 'yellow', 'guards' => 'isOneGuard', ], [ 'target' => 'red', 'guards' => 'isTwoGuard', ], [ 'target' => 'pedestrian', ], ], ], ], 'yellow' => [], 'red' => [], 'pedestrian' => [], ], ], behavior: [ 'guards' => [ 'isOneGuard' => function (ContextManager $context, array $event): bool { return $context->get('value') === 1; }, 'isTwoGuard' => function (ContextManager $context, array $event): bool { return $context->get('value') === 2; }, ], ], );
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.