PHPackages                             survos/state-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. survos/state-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

survos/state-bundle
===================

Add some tools managing state machines using the Symfony Workflow Component

2.11.4(1w ago)11.4k↓51.8%5MITPHPPHP ^8.5

Since Sep 5Pushed 1w agoCompare

[ Source](https://github.com/survos/state-bundle)[ Packagist](https://packagist.org/packages/survos/state-bundle)[ GitHub Sponsors](https://github.com/kbond)[ RSS](/packages/survos-state-bundle/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (2)Dependencies (234)Versions (281)Used By (5)

workflow-helper-bundle
======================

[](#workflow-helper-bundle)

Configure a workflow using PHP attributes. Prefer separating the durable workflow definition from the event listener/orchestrator:

- `*Flow` is the attribute definition class, for example `ImageFlow` or `SubmissionFlow`.
- `*Workflow` is the listener/service class that reacts to transitions, queues work, and applies app policy, for example `ImageWorkflow`.

Older apps may still use `*WF`, `*WorkflowInterface`, or a single class that both defines and handles the workflow. New code should use `*Flow` for the definition because it is short, readable, and leaves `Workflow` for the runtime service.

auto-registration!

Workflow Constants In Twig
--------------------------

[](#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('ImageFlow', 'TRANSITION_REMOVE') %}
```

Available helpers:

- `workflow_const(subjectOrWorkflow, constantName)`: resolves a PHP constant from the workflow definition class
- `workflow_name(subjectOrWorkflow)`: resolves the workflow name from a subject or returns the provided workflow name
- `survos_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
------------

[](#how-it-works)

During bundle prepend/compile time, `AttributesWorkflowConfigBuilder` now publishes an internal map of:

- `workflow name => workflow definition class`
- `supported entity class => workflow definition class[]`

`WorkflowHelperService` uses that map to resolve the workflow definition class for either:

- a workflow name like `ImageFlow`
- 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
-----

[](#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
------

[](#vibing)

Doctrine-free jsonl workflow:

@todo:

for easyadmin integration, also see

```
