Skip to content

Getting Started

cakephp-workflow is a CakePHP plugin for state-machine style workflows.

What It Does

The plugin tracks where records are in their lifecycle:

  • An order: pendingpaidshippedcompleted
  • A ticket: openin_progressresolved
  • An approval: draftsubmittedapproved

At any moment, a record is in exactly one state. You control how it moves between states.

Core Features

FeatureDescription
PHP 8 AttributesDefine workflows in PHP classes
NEON/YAMLOr use config files
GuardsConditional transitions
CommandsActions on transitions
ORM BehaviorCakePHP table integration
Admin UIVisual dashboard
CLI ToolsManagement commands

Typical Flow

1. Define a workflow (attributes or config file)
2. Attach behavior to your table
3. Use workflow.can() and workflow.apply()
4. Inspect via admin UI or CLI

What It Is Good For

  • Clear lifecycle for records (orders, tickets, payouts, approvals)
  • CakePHP ORM integration through a behavior
  • PHP-first definitions with editor support
  • Workflow inspection from an admin dashboard

What It Is Not

This is a single-state workflow engine:

  • An entity is in one state at a time
  • Transitions move from one state to one target state
  • It is not a multi-place workflow-net engine

For most application lifecycles, this is exactly the right level of complexity.

Quick Example

php
// Get a workflow for an entity
$workflow = $this->workflowRegistry->get($order);

// Check and apply a transition
if ($workflow->can('pay')) {
    $result = $workflow->apply('pay');
    if ($result->isSuccess()) {
        $this->Orders->save($order);
    }
}

Next Steps

  1. Installation - Get the plugin running
  2. Concepts - Understand states, transitions, guards
  3. Quick Start - Build your first workflow
  4. Behavior Integration - Full API reference

Released under the MIT License.