Search by

small / swoole-workflow-manager

small

Persistent, versioned and multi-format BPMN document management for Small Swoole Workflow

dev-main 2026-11-18 12:13 UTC

This package is not auto-updated.

Last update: 2026-11-25 09:32:19 UTC


README

small/swoole-workflow-manager manages versioned BPMN definitions in a database using Small ORM. It imports, validates, exports, and loads BPMN process definitions consumed by Small Swoole Workflow.

The package does not store BPMN definitions on the filesystem and does not manage running instances, tokens, jobs, or task execution. Symfony is not a dependency; its future bundle will only assemble and inject the services.

Features

OperationBehaviour
persist()Validate and store an immutable BPMN definition in Small ORM's bpmn_process_version table
validate()Secure BPMN parser, structural checks, reachability, and diagnostics
load()Load a pinned version as the engine's ProcessDefinition (no write)
versions()List published database revisions
export()Export the canonical XML or an XML-preserving JSON/YAML envelope
ImportAccept BPMN XML, JSON envelope, and YAML envelope
IntegritySHA-256 of original BPMN XML, enforced on database reads

Storage: every successful import is stored as original BPMN XML, regardless of input format. JSON and YAML represent lossless interchange envelopes; they do not introduce competing BPMN execution formats. BPMN-DI and custom XML extensions are retained.

The database schema is owned by small/swoole-workflow. The manager reuses the existing ProcessVersionManager / OrmDefinitionAdapter; it never creates its own connection configuration, a second definitions table, or any raw SQL access.

Database connection injection

The constructor receives a configured Small ORM ConnectionFactory, to be supplied by the application or, later, a service in the Symfony bundle:

use Small\SwooleEntityManager\Factory\ConnectionFactory;
use Small\SwooleWorkflow\Infrastructure\Driver\BpmnXmlParserDriver;
use Small\SwooleWorkflowManager\Application\Entity\BpmnDocumentFormat;
use Small\SwooleWorkflowManager\Application\UseCase\WorkflowDefinitionValidator;
use Small\SwooleWorkflowManager\Application\UseCase\WorkflowManager;
use Small\SwooleWorkflowManager\Infrastructure\Format\DefaultBpmnCodecs;
use Small\SwooleWorkflowManager\Infrastructure\Persistence\OrmBpmnDocumentStore;

/** @var ConnectionFactory $connectionFactory A configured, injected Small ORM connection factory */
$parser = new BpmnXmlParserDriver();
$codecs = DefaultBpmnCodecs::create();

$manager = new WorkflowManager(
    new OrmBpmnDocumentStore($connectionFactory, $parser),
    $codecs,
    new WorkflowDefinitionValidator($parser),
);

$report = $manager->validate($bpmnXml, BpmnDocumentFormat::XML);
$version = $manager->persist($bpmnXml, BpmnDocumentFormat::XML)->version;

// JSON/YAML can also be imported, but are stored as canonical XML.
$yaml = $manager->export('order', $version, BpmnDocumentFormat::YAML);
$json = $manager->export('order', $version, BpmnDocumentFormat::JSON);
$definition = $manager->load('order', $version); // Ready for the BPMN engine.

The Small ORM connection factory is the sole database configuration dependency. The future small/swoole-workflow-bundle will obtain it from the existing Small ORM integration and inject it into OrmBpmnDocumentStore; it must not configure another database pool.

Advanced applications that already inject DefinitionGatewayInterface can reuse EngineDefinitionStore (the internal gateway adapter) directly.

Persistence semantics

  • The XML is checked before any insert; invalid or unsafe BPMN XML never reaches the persistence layer.
  • Database revisions are immutable and scoped by process ID.
  • Reimporting exactly the same XML as the latest revision returns the existing version. Switching to a previous historical XML creates a new revision.
  • The existing database uniqueness constraint on (process_id, version) handles concurrent version conflicts; callers must handle/retry conflicts after reloading the latest version.
  • A stored definition is already published to the engine's canonical version store. The previous publishToEngine() method has been removed to prevent double publication.
  • Running process instances are never implicitly migrated to a newer BPMN version; they stay pinned.
  • load() and export() verify the stored XML and SHA-256 before returning content.
  • No filesystem persistence, temporary BPMN files, flock or filesystem paths are used.

Required database schema

Use the upstream Small Swoole Workflow schema. The manager needs the existing bpmn_process_version table:

CREATE TABLE IF NOT EXISTS bpmn_process_version (
    id CHAR(36) NOT NULL PRIMARY KEY,
    process_id VARCHAR(190) NOT NULL,
    version INT UNSIGNED NOT NULL,
    checksum CHAR(64) NOT NULL,
    xml LONGTEXT NOT NULL,
    UNIQUE KEY uq_bpmn_process_version (process_id, version)
) ENGINE=InnoDB;

The database and driver are configured outside this package through Small ORM. No Doctrine ORM, DBAL, or migrations are introduced.

Quality and limitations

vendor/bin/phpstan analyse --no-progress runs at level max; vendor/bin/pest tests/Unit tests/Functional exercises formats and definition management. For production use, qualify the Small ORM persistence against the application's actual MySQL/PostgreSQL service, including concurrent publishing and failure recovery.

Validation covers the executable subset supported by Small Swoole Workflow; it is not an OMG BPMN 2.0 certification. BPMN handlers and called-process versions remain application/runtime responsibilities.

License: MIT — copyright Sébastien Kus.