survos / state-bundle
Add some tools managing state machines using the Symfony Workflow Component
Fund package maintenance!
Requires
- php: ^8.4
- doctrine/orm: ^2.12 || ^3.3
- survos/core-bundle: ^2.0
- symfony/console: ^7.3||^8.0
- symfony/http-kernel: ^7.3||^8.0
- symfony/messenger: ^7.3||^8.0
- symfony/process: ^7.3||^8.0
- symfony/string: ^7.3||^8.0
- symfony/workflow: ^7.3||^8.0
- symfony/yaml: ^7.3||^8.0
Requires (Dev)
- nette/php-generator: ^4.1
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^13.0
- psr/log: ^3.0
- roave/better-reflection: ^6.0
- survos/tabler-bundle: ^2.0
- symfony/browser-kit: ^7.3||^8.0
- symfony/config: ^7.3||^8.0
- symfony/dependency-injection: ^7.3||^8.0
- symfony/form: ^7.3||^8.0
- symfony/framework-bundle: ^7.3||^8.0
- symfony/maker-bundle: ^1.5
- symfony/twig-bundle: ^7.3||^8.0
- symfony/ux-chartjs: ^2.0|^3.0
- symfony/var-dumper: ^7.3||^8.0
- zenstruck/class-metadata: ^1.1
- zenstruck/messenger-monitor-bundle: ^v0.6.0
- dev-main
- 2.0.206
- 2.0.205
- 2.0.204
- 2.0.203
- 2.0.202
- 2.0.201
- 2.0.200
- 2.0.199
- 2.0.198
- 2.0.197
- 2.0.196
- 2.0.195
- 2.0.194
- 2.0.193
- 2.0.192
- 2.0.191
- 2.0.190
- 2.0.189
- 2.0.188
- 2.0.187
- 2.0.186
- 2.0.185
- 2.0.184
- 2.0.183
- 2.0.182
- 2.0.181
- 2.0.180
- 2.0.179
- 2.0.178
- 2.0.177
- 2.0.176
- 2.0.175
- 2.0.174
- 2.0.173
- 2.0.172
- 2.0.171
- 2.0.170
- 2.0.169
- 2.0.168
- 2.0.167
- 2.0.166
- 2.0.165
- 2.0.164
- 2.0.163
- 2.0.162
- 2.0.161
- 2.0.160
- 2.0.159
- 2.0.158
- 2.0.156
- 2.0.155
- 2.0.154
- 2.0.146
- 2.0.145
- 2.0.144
- 2.0.143
- 2.0.142
- 2.0.141
- 2.0.140
- 2.0.139
- 2.0.138
- 2.0.137
- 2.0.136
- 2.0.135
- 2.0.134
- 2.0.133
- 2.0.132
- 2.0.131
- 2.0.130
- 2.0.129
- 2.0.128
- 2.0.127
- 2.0.126
- 2.0.125
- 2.0.124
- 2.0.123
- 2.0.122
- 2.0.121
- 2.0.120
- 2.0.119
- 2.0.117
- 2.0.116
- 2.0.115
- 2.0.114
- 2.0.113
- 2.0.112
- 2.0.111
- 2.0.110
- 2.0.109
- 2.0.108
- 2.0.107
- 2.0.106
- 2.0.105
- 2.0.104
- 2.0.103
- 2.0.102
- 2.0.101
- 2.0.100
- 2.0.99
- 2.0.98
- 2.0.97
- 2.0.96
- 2.0.95
- 2.0.94
- 2.0.93
- 2.0.92
- 2.0.91
- 2.0.90
- 2.0.89
- 2.0.88
- 2.0.87
- 2.0.86
- 2.0.85
- 2.0.84
- 2.0.83
- 2.0.82
- 2.0.81
- 2.0.80
- 2.0.79
- 2.0.78
- 2.0.77
- 2.0.76
- 2.0.75
- 2.0.74
- 2.0.73
- 2.0.72
- 2.0.71
- 2.0.70
- 2.0.69
- 2.0.68
- 2.0.67
- 2.0.66
- 2.0.65
- 2.0.64
- 2.0.63
- 2.0.62
- 2.0.61
- 2.0.60
- 2.0.59
- 2.0.58
- 2.0.57
- 2.0.56
- 2.0.55
- 2.0.54
- 2.0.53
- 2.0.51
- 2.0.50
- 2.0.49
- 2.0.48
- 2.0.47
- 2.0.46
- 2.0.45
- 2.0.44
- 2.0.43
- 2.0.42
- 2.0.41
- 2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- 2.0.36
- 2.0.35
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.31
- 2.0.30
- 2.0.29
- 2.0.28
- 2.0.27
- 2.0.26
- 2.0.25
- 2.0.24
- 2.0.23
- 2.0.22
- 2.0.21
- 2.0.20
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 1.7
- 1.5.600
This package is auto-updated.
Last update: 2026-04-27 15:14:59 UTC
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!
Workflow Constants In Twig
The bundle now exposes additive Twig helpers for resolving workflow definition constants without hard-coding raw place or transition strings in templates.
{% set removePlace = workflow_const(image, 'PLACE_REMOVE') %}
{% if image.marking != removePlace %}
...
{% endif %}
You can also resolve by workflow name:
{% set removeTransition = workflow_const('ImageWorkflow', 'TRANSITION_REMOVE') %}
Available helpers:
workflow_const(subjectOrWorkflow, constantName): resolves a PHP constant from the workflow definition classworkflow_name(subjectOrWorkflow): resolves the workflow name from a subject or returns the provided workflow namesurvos_workflow_metadata(workflowName, key, metadataSubject): existing metadata helper for workflow/place/transition metadata
This is additive. Existing metadata helpers and app-level Twig extensions can remain in place.
How It Works
During bundle prepend/compile time, AttributesWorkflowConfigBuilder now publishes an internal map of:
workflow name => workflow definition classsupported entity class => workflow definition class[]
WorkflowHelperService uses that map to resolve the workflow definition class for either:
- a workflow name like
ImageWorkflow - an entity instance like
App\Entity\Image
That lets Twig resolve constants from the actual PHP workflow definition instead of relying on brittle string literals in templates.
Tests
The bundle now includes PHPUnit 13-compatible unit tests covering:
- compile-time workflow definition mapping
- constant resolution in
WorkflowHelperService - Twig helper exposure in
WorkflowExtension
Run them from the bundle root:
composer install vendor/bin/phpunit
Vibing
Doctrine-free jsonl workflow: https://claude.ai/share/9c89f52c-1655-44b6-bb86-d773d29bc20b
@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\StateBundle\Attribute\Place; use Survos\StateBundle\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