small / swoole-workflow-bundle
Symfony integration for Small Swoole Workflow and its database-backed BPMN manager
Package info
git.small-project.dev/lib/small-swoole-workflow-bundle.git
Type:symfony-bundle
pkg:composer/small/swoole-workflow-bundle
Requires
- php: >=8.4
- ext-dom: *
- ext-swoole: *
- small/swoole-entity-manager-bundle: ^3.1
- small/swoole-workflow: dev-main
- small/swoole-workflow-manager: dev-main
- symfony/config: ^7.4 || ^8.1
- symfony/console: ^7.4 || ^8.1
- symfony/dependency-injection: ^7.4 || ^8.1
- symfony/http-kernel: ^7.4 || ^8.1
Requires (Dev)
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.2
- symfony/framework-bundle: ^7.4 || ^8.1
- symfony/yaml: ^7.4 || ^8.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-25 09:22:01 UTC
README
Symfony integration for Small Swoole Workflow and the database-backed Workflow Manager.
Status: initial development integration. The engine and manager currently expose only dev-main, so do not release this bundle as stable until both dependencies have versioned, validated releases. The engine's BPMN execution subset is experimental and does not claim full OMG conformity.
Features and boundaries
- Symfony 7.4 LTS / 8.x integration using AbstractBundle and DI compiler passes.
- Shares the existing Small ORM Core ConnectionFactory exposed by small/swoole-entity-manager-bundle ^3.1. No additional connection pool, SQL or Doctrine.
- Real ORM-backed BPMN XML/JSON/YAML import, validation, immutable definition versions, export and load via the existing Workflow Manager.
- Registers per-process BPMN state voters, action policies, ordered business rules and allowlisted PHP handlers.
- Exposes the correlated and legacy orchestrators, durable jobs, inbound events, outbox, runtime recovery and explicit workers.
- No worker or coroutine starts while handling HTTP requests or compiling Symfony's container.
- Business state recovery creates an unpersisted correlated token. The application owns authentication, authorization, revision fencing, transaction, persisted job reconciliation and audit logging.
- Handler and event callbacks must be idempotent: callbacks can be retried.
Requirements
PHP >=8.4, ext-swoole, ext-dom, Symfony 7.4 LTS or supported 8.x versions, and Small ORM Core 3.3.1+ via small/swoole-entity-manager-bundle ^3.1. Test Docker uses PHP 8.4, Swoole 6.2.6 and MySQL 8.4.
The BPMN engine and Workflow Manager own the database schema. Install the engine schema as a separate deployment step; only a disposable test schema fixture exists in this project.
Install and configure
Register both SmallSwooleEntityManagerBundle and SmallSwooleWorkflowBundle in the Symfony application. While upstream packages are dev-only, supply the requisite VCS repositories and explicitly opt in to dev-main as shown in composer.json. No stable Packagist release is claimed.
Example configuration (config/packages/small_swoole_workflow.yaml):
small_swoole_workflow:
connection: default
runtime:
correlated: true
definitions:
validate_on_import: true
processes:
order:
process_id: order
user_actions:
approve: order.approve
workers:
enabled: false
poll_interval_ms: 1000
lease_seconds: 30
max_attempts: 3
outbox:
enabled: true
lease_seconds: 30
recovery:
enabled: true
batch_size: 100
The connection name must match small_swoole_entity_manager.default_connection. A second connection pool is forbidden. Manager validation cannot be disabled. Runtime configuration does not itself start workers: deployment must supervise them explicitly. The engine's low-level job driver retains its own default lease duration until an application provides a configured queue adapter.
Tagged services in config/services.yaml:
services:
App\Workflow\OrderStateVoter:
tags:
- { name: small_swoole_workflow.state_voter, process: order, node: approve }
App\Workflow\OrderActionPolicy:
tags:
- { name: small_swoole_workflow.action_voter, process: order }
App\Workflow\OrderBusinessRule:
tags:
- { name: small_swoole_workflow.business_rule, process: order, priority: 10 }
App\Workflow\OrderHandler:
tags:
- { name: small_swoole_workflow.handler, process: order, name: execute }
Compiler checks reject duplicate or unknown registrations and invalid interfaces. Business rules require unique integer priorities; action policies are mandatory before requesting a human-task vote. All persisted PHP handler service classes must be tagged for the process before resolution through PhpHandlerResolverDriver.
Public PHP services
- Small\SwooleWorkflowManager\Application\UseCase\WorkflowManager
- Small\SwooleWorkflowBundle\Service\ProcessRegistry
- Small\SwooleWorkflowBundle\Service\RuntimeServices
- Small\SwooleWorkflow\Infrastructure\Adapter\Interface\OrmConnectionProviderInterface
- Small\SwooleWorkflow\Infrastructure\Service\OrmCorrelatedProcessOrchestrator
- Small\SwooleWorkflow\Infrastructure\Service\OrmDurableJobQueue
- Small\SwooleWorkflow\Infrastructure\Service\OrmInboundEventReceiver
- Small\SwooleWorkflow\Infrastructure\Service\OrmOutboxPublisher
- Small\SwooleWorkflow\Infrastructure\Service\OrmInstanceRecovery
The DI factory uses the real Small ORM Core ConnectionFactory from the existing ORM bundle, not an independent connection configuration.
The manager supports validate(), persist(), versions(), load() and export(). A persisted definition is immediately visible as an immutable version to the engine; existing instances remain pinned to their original version.
Business state voter API
$registry = $container->get(\Small\SwooleWorkflowBundle\Service\ProcessRegistry::class);
$definition = $workflowManager->load('order', 1);
$resolver = $registry->stateResolver('order');
$marking = $resolver->resolve($definition, [$order, $approval]);
// Or after an explicitly authorized operator choice:
$marking = $resolver->choose($definition, [$order, $approval], 'approve');
On missing or ambiguous positions the resolver throws BpmnStateResolutionException with getCandidates(). The bundle never persists either marking. Only root simple task positions supported by the underlying resolver are accepted. The application must revalidate votes within an authorized Small ORM transaction before persisting a recovery.
Explicit workers
$runtime = $container->get(\Small\SwooleWorkflowBundle\Service\RuntimeServices::class);
$worker = $runtime->jobs($applicationIdempotentActivityCallback);
$worker->runOnce(); // or ->runUntil($stop)
$outbox = $runtime->outboxWorker($applicationIdempotentPublishCallback);
$outbox->runOnce();
$runtime->preparedCompletions()->runOnce();
$runtime->scopeProjections()->runOnce();
// Legacy recovery; correlated instance recovery is explicit, pinned, and per-instance.
$runtime->recovery()->recover();
$runtime->correlatedOrchestrator()->recover($instanceId, $pinnedDefinition, $version);
A userTask policy is assembled on demand using ProcessRegistry::actionVoter($process). Use RuntimeServices::handlerResolver($process, $registry) to build the upstream allowlisted persisted PHP handler resolver for that process. These methods preserve the engine's existing contracts and errors.
Nothing launches automatically at kernel boot. The embedding application's process manager / supervisor owns actual worker lifecycle, retry policies, event transports and incident recovery.
Enable executable hooks after GitLab API checkout
GitLab's content API does not set executable bits on newly created shell files. After the initial checkout, execute:
sh bin/setup-hooks
This makes the local bin/composer, bin/console, bin/release and Git hooks executable, and enables .githooks as the repository's hooks directory. The CI enforces the same checks independently of local hooks.
Run tests locally
docker compose up --build -d
bin/composer install
docker compose exec -T app vendor/bin/phpstan analyse --no-progress
docker compose exec -T app vendor/bin/pest --testsuite=Unit
docker compose exec -T app vendor/bin/pest --testsuite=Functional
docker compose exec -T app php tests/Database/prepare-database.php
docker compose exec -T app vendor/bin/pest --testsuite=Database
Tests run against a disposable MySQL 8.4 service. Never run the test database bootstrap against production. In CI every commit must run PHPStan max, copyright check, Pest unit, functional and real MySQL tests; tagged releases add build and generic package publication after tests.
License: MIT. Copyright (c) 2026 Sébastien Kus.
Project XML import (boot)
The bundle scans the configurable config/workflows directory when the Symfony kernel boots:
small_swoole_workflow:
definitions:
directory: config/workflows
load_on_boot: true
Only missing BPMN process IDs are imported to the versioned Small ORM store. Existing definitions are intentionally retained, even if the local XML differs: publish a new revision explicitly via WorkflowManager instead. An invalid XML causes boot to fail rather than silently load a partial definition set.
Maintenance command, destructive and explicit:
php bin/console small:workflow:database:clear --force
This command currently clears BPMN definition history only. It does not remove running workflow instances, jobs, outbox events, or other application tables. Stop worker processes and back up the database before using it. On the next kernel boot XML files will be imported again.
Catalogue de handlers PHP du projet
L'editeur small/swoole-workflow-ui peut generer un catalogue config/workflows/handlers.json dans l'application Symfony :
{
"version": 1,
"handlers": [{
"id": "019a0000-aaaa-7bbb-8ccc-0123456789ab",
"processId": "demo_order",
"service": "App\\Workflow\\OrderHandler",
"method": "execute"
}]
}
Au compile du conteneur, WorkflowCompilerPass autorise uniquement les classes declarees dans ce fichier projet : il les associe aux processus et au registre Symfony DI. Au boot, WorkflowXmlBootstrap enregistre les UUIDv7 immuables dans la table bpmn_handler_definition avant d'importer les BPMN XML absents.
L'extension BPMN attendue est : extensionElements contenant un element small:handler avec ref=UUIDv7 ; le prefixe small est lie au namespace urn:small:swoole-workflow:1. Ne jamais mettre de classe PHP executable dans un XML BPMN de provenance externe. Une reaffectation d'un UUIDv7 existant a une autre classe/methode est interdite. Recompiler le cache Symfony lors de l'ajout d'un service au catalogue.
Handler dependency injection
Implement WorkflowHandlerInterface and declare constructor dependencies normally. Existing Symfony service definitions and FQCN aliases are preserved; catalog-only classes are registered with autowiring. Use a class alias to resolve ambiguous service definitions. Keep handlers stateless across Swoole coroutines. Inject WorkflowWorkerFactory and call worker() to dispatch jobs using their BPMN process ID, or dispatcher($processName) for an explicitly scoped dispatcher. The core supplies TaskExecutionContext and validates TaskExecutionResult; no Symfony container is passed to it.