Search by

adachsoft / workflow-definition-repository-json

Arkadiusz Adach

JSON file-based implementation of WorkflowDefinitionRepositoryInterface.

Package info

gitlab.com/a.adach/workflow-definition-repository-json

Issues

pkg:composer/adachsoft/workflow-definition-repository-json

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

v2.0.0 2026-10-29 09:51 UTC

This package is not auto-updated.

Last update: 2026-10-29 08:53:30 UTC


README

A JSON file-based implementation of WorkflowDefinitionRepositoryInterface from adachsoft/workflow. Each workflow definition is stored in a separate JSON file.

Requirements

  • PHP 8.3 or later
  • adachsoft/workflow ^5.2

Installation

composer require adachsoft/workflow-definition-repository-json

Usage

<?php

declare(strict_types=1);

use AdachSoft\WorkflowDefinitionRepositoryJson\JsonFileWorkflowDefinitionRepository;
use AdachSoft\WorkflowDefinitionRepositoryJson\Mapper\WorkflowDefinitionJsonMapper;

$repository = new JsonFileWorkflowDefinitionRepository(
    __DIR__ . '/var/workflows',
    new WorkflowDefinitionJsonMapper(),
);

$definition = $repository->get('invoice');
$repository->save($definition);
$definitions = $repository->list();

get() returns a WorkflowDefinitionVo for the requested workflow ID and throws WorkflowNotFoundException when its JSON file does not exist. save() writes a workflow definition to <workflows-directory>/<workflow-id>.json, creating the directory when needed. list() returns workflow definitions keyed by ID in sorted order; it returns an empty array if the directory does not exist.

JSON format

A workflow file contains a steps object keyed by step name. It may also contain input_schema and output_schema objects:

{
  "input_schema": {
    "customer_id": {
      "type": "string",
      "required": true,
      "description": "Customer identifier"
    }
  },
  "output_schema": {
    "status": {
      "type": "string",
      "required": true,
      "description": "Batch status"
    },
    "images": {
      "type": "array",
      "required": true,
      "description": "Saved images"
    }
  },
  "steps": {
    "finish": {
      "type": "finish",
      "config": {
        "output": {
          "status": "done",
          "images": []
        }
      }
    }
  }
}

The mapper converts workflow steps and nested JSON objects to workflow payload values, and maps schema declarations to workflow schema value objects. If input_schema is omitted, it is treated as empty; saving a workflow writes the input_schema field. If output_schema is omitted, no workflow output contract is declared and saving omits the key. An explicit empty output schema is serialized as [], declares an empty output contract, and is preserved on save and load; it is distinct from an omitted schema. Output schema fields use the same format as input schema fields. Invalid schema field definitions are rejected by the schema contract in adachsoft/workflow. Malformed JSON or an invalid top-level workflow structure raises RuntimeException.

Tests

Run the PHPUnit suite with:

vendor/bin/phpunit tests