survos / state-bundle
Add some tools managing state machines using the Symfony Workflow Component
Fund package maintenance!
kbond
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.4
- doctrine/orm: ^2.12 || ^3.3
- survos/core-bundle: ^1.5
- symfony/console: ^7.3
- symfony/http-kernel: ^7.3
- symfony/messenger: ^7.3
- symfony/process: ^7.3
- symfony/string: ^7.3
- symfony/workflow: ^7.3
- symfony/yaml: ^7.3
Requires (Dev)
- jwage/phpamqplib-messenger: ^0.8.5
- nette/php-generator: ^4.1
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12
- psr/log: ^3.0
- roave/better-reflection: ^6.0
- survos/bootstrap-bundle: ^1.4
- symfony/browser-kit: ^7.3
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/form: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/maker-bundle: ^1.5
- symfony/twig-bundle: ^7.3
- symfony/ux-chartjs: ^2.21
- symfony/var-dumper: ^7.3
- zenstruck/class-metadata: ^1.1
- zenstruck/messenger-monitor-bundle: ^0.5.4
Conflicts
- survos/api-grid-bundle: <1.2.57
- survos/auth-bundle: <1.2.57
- survos/barcode-bundle: <1.2.57
- survos/bootstrap-bundle: <1.2.57
- survos/command-bundle: <1.2.57
- survos/crawler-bundle: <1.2.57
- survos/doc-bundle: <1.2.57
- survos/faker-bundle: <1.2.57
- survos/grid-bundle: <1.2.57
- survos/grid-group-bundle: <1.2.57
- survos/html-prettify-bundle: <1.2.57
- survos/import-bridge: <1.2.57
- survos/inspection-bundle: <1.2.57
- survos/location-bundle: <1.2.57
- survos/maker-bundle: <1.2.57
- survos/providence-bundle: <1.2.57
- survos/ruler-bundle: <1.2.57
- survos/stripe-product: <1.2.57
- survos/tree-bundle: <1.2.57
- survos/wiki-bundle: <1.2.57
README
Configure a workflow using PHP attributes. Use just one class to configure and act on the workflow events. (Or create an interface with the configuration for easy separation).
auto-registration!
@todo: https://joppe.dev/2024/10/11/dynamic-workflows-with-symfony-workflow-component/
for easyadmin integration, also see https://github.com/WandiParis/EasyAdminPlusBundle
<?php // SubmissionWorkflowInterface.php namespace App\Workflow; use Survos\WorkflowBundle\Attribute\Place; use Survos\WorkflowBundle\Attribute\Transition; interface SubmissionWorkflowInterface { const WORKFLOW_NAME='SubmissionWorkflow'; #[Place(initial: true, metadata: ['description' => "starting place after submission"])] const PLACE_NEW='new'; #[Place(metadata: ['description' => "waiting for admin approval"])] const PLACE_WAITING='waiting'; const PLACE_APPROVED='approved'; const PLACE_REJECTED='rejected'; const PLACE_WITHDRAWN='withdrawn'; #[Transition(from:[self::PLACE_NEW], to: self::PLACE_WAITING)] const TRANSITION_SUBMIT='submit'; #[Transition(from:[self::PLACE_NEW], to: self::PLACE_APPROVED, guard: "is_granted('ROLE_ADMIN')")] const TRANSITION_APPROVE='approve'; #[Transition(from:[self::PLACE_NEW], to: self::PLACE_REJECTED, guard: "is_granted('ROLE_ADMIN')")] const TRANSITION_REJECT='reject'; #[Transition(from:[self::PLACE_NEW, self::PLACE_APPROVED], to: self::PLACE_WITHDRAWN, guard: "is_granted('ROLE_USER')")] const TRANSITION_WITHDRAW='withdrawn'; #[Transition(from:[self::PLACE_REJECTED, self::PLACE_APPROVED], to: self::PLACE_NEW)] const TRANSITION_RESET='reset'; }
Now create a class that implements the interface (to get the constants) and acts on the events.
symfony new workflow-demo --webapp --php=8.4 && cd workflow-demo composer config extra.symfony.allow-contrib true bin/console importmap:require d3 composer config minimum-stability beta bin/console make:controller d3 -i symfony server:start -d symfony open:local --path=/d3 ../survos/bin/lb.sh workflow-helper # composer req survos/state-bundle bin/console make:controller d3 -i cat > templates/d3 .html.twig <<END {% extends 'base.html.twig' %} {% block body %} workflow here. {% endblock %} END symfony server:start -d symfony open:local --path=/d3
Notes
Since the workflow may use a message bus, a reminder on how to configure that with the Symfony CLI: https://symfony.com/doc/current/setup/symfony_server.html#symfony-server_configuring-workers
https://github.com/survos/SurvosWorkflowHelperBundle/network/dependents https://github.com/codereviewvideos/symfony-workflow-example