Workflow in real life

Artem Dekhtyar

Pavel Stepanets

Who we are?

 

https://connect.sensiolabs.com/club/symfonybro

Our competences

5+ years in development

DDD

Software architect

PHP, Java, C#

Symfony, Yii2

Legacy projects migration

GERP

Trouble ticket system - GERP

  • SaaS solution
  • RESTful api + Mobile App
  • Integrations (SOAP, Xml, Json, etc.)
  • Reporting
  • Scheduling
  • Billing
  • Ticket QA
  • And many other features

GERP

Was migrated from this

To Symfony!

Problems

Complex graph

Problems

  • Nontrivial state graph

Data and Comment

Requirements

DateTime

Redirect

Modal window

Complex forms

Problems

  • Nontrivial state graph
  • Additional transition data
  • Comment to ticket on ticket changes

Pluggable workflows

for bundles

Problems

  • Nontrivial state graph
  • Additional transition data
  • Comment to ticket on ticket changes
  • Pluggable workflow configuration

Transition security

Transition guard

Problems

  • Nontrivial state graph
  • Additional transition data
  • Comment to ticket on ticket changes
  • Pluggable workflow configuration
  • Security restrictions

Research

Form Component

for additional transition data

Commands and Handlers

to wrap Comment object

Compiler passes

for setup Workflow services from bundle configuration 

\Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension::registerWorkflowConfiguration

Custom workflow guard listeners

for transitions guarding

gtt/workflow-extensions-bundle

Expression Language and 

Workflow guard events

Development

(solution)

Command bus

by League of Extraordinary packages

Tactician

http://tactician.thephpleague.com/

WorkflowMiddleware

public function execute($command, callable $next)
{
    //...
    
    $result = $next($command);
    
    //...
    
    try {
        $workflow = $this->registry->get($task, $workflowName);
        $workflow->apply($task, $command->getTransition());
    } catch (Exception $exception) {
        throw new TaskException( /* ... */ );
    }
}

Example transition 

Forms

SymfonyBro\TaskBundle\Form\TransitionType

Choices are enabled transitions of given subject extracted from Workflow component

Building command flow

(comment)

Pluggable workflows

  • Copy-paste from FrameworkExtension::registerWorkflowConfiguration into AbstractRegisterWorkflowPass
  • custom transitions options
  • guard expression option
  • allow any time extension, eg. places coloring

Security

Gorserv/Gerp/TaskServiceBundle/Resources/config/workflow.yml

    transitions:
        delay:
            from: new
            to: delayed
            guard: 'is_granted(["ROLE_DISPATCHER"])'
        dispatch:
            from: new
            to: scheduled
            guard: 'is_granted(["ROLE_DISPATCHER"])'
        to_work:
            from: scheduled
            to: in_work
            guard: 'is_granted(["ROLE_TECH"])'

TransitionToRolePass

builds roles from specified workflow transitions and inject them into containers roles hierarchy

workflow

cancel:
    from: new
    to: canceled

to_agreement:
    from: new
    to: wait_agreement

dispatch:
    from: new
    to: scheduled

security.role_hierarchy.roles

ROLE_SERVICE_TRANSITION_CANCEL:



ROLE_SERVICE_TRANSITION_TO_AGREEMENT:



ROLE_SERVICE_TRANSITION_DISPATCH:

That's all folks!

https://gitlab.com/symfony-bro

https://goo.gl/d52JVV (workflow-extensions-bundle)

https://gorserv.com/

https://goo.gl/PcBcNk (slides)