2016-11-17 10:10:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Component\Workflow\Tests;
|
|
|
|
|
|
|
|
use Symfony\Component\Workflow\Definition;
|
2018-12-09 17:01:32 +00:00
|
|
|
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
|
2016-11-17 10:10:08 +00:00
|
|
|
use Symfony\Component\Workflow\Transition;
|
|
|
|
|
|
|
|
trait WorkflowBuilderTrait
|
|
|
|
{
|
2016-11-21 16:19:45 +00:00
|
|
|
private function createComplexWorkflowDefinition()
|
2016-11-17 10:10:08 +00:00
|
|
|
{
|
|
|
|
$places = range('a', 'g');
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$transitions = [];
|
|
|
|
$transitions[] = new Transition('t1', 'a', ['b', 'c']);
|
|
|
|
$transitions[] = new Transition('t2', ['b', 'c'], 'd');
|
2018-12-09 17:01:32 +00:00
|
|
|
$transitionWithMetadataDumpStyle = new Transition('t3', 'd', 'e');
|
|
|
|
$transitions[] = $transitionWithMetadataDumpStyle;
|
2016-11-17 10:10:08 +00:00
|
|
|
$transitions[] = new Transition('t4', 'd', 'f');
|
|
|
|
$transitions[] = new Transition('t5', 'e', 'g');
|
|
|
|
$transitions[] = new Transition('t6', 'f', 'g');
|
|
|
|
|
2018-12-09 17:01:32 +00:00
|
|
|
$transitionsMetadata = new \SplObjectStorage();
|
|
|
|
$transitionsMetadata[$transitionWithMetadataDumpStyle] = [
|
|
|
|
'label' => 'My custom transition label 1',
|
|
|
|
'color' => 'Red',
|
|
|
|
'arrow_color' => 'Green',
|
|
|
|
];
|
|
|
|
$inMemoryMetadataStore = new InMemoryMetadataStore([], [], $transitionsMetadata);
|
|
|
|
|
|
|
|
return new Definition($places, $transitions, null, $inMemoryMetadataStore);
|
2016-11-17 10:10:08 +00:00
|
|
|
|
|
|
|
// The graph looks like:
|
|
|
|
// +---+ +----+ +---+ +----+ +----+ +----+ +----+ +----+ +---+
|
|
|
|
// | a | --> | t1 | --> | c | --> | t2 | --> | d | --> | t4 | --> | f | --> | t6 | --> | g |
|
|
|
|
// +---+ +----+ +---+ +----+ +----+ +----+ +----+ +----+ +---+
|
|
|
|
// | ^ | ^
|
|
|
|
// | | | |
|
|
|
|
// v | v |
|
|
|
|
// +----+ | +----+ +----+ +----+ |
|
|
|
|
// | b | ----------------+ | t3 | --> | e | --> | t5 | -----------------+
|
|
|
|
// +----+ +----+ +----+ +----+
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:19:45 +00:00
|
|
|
private function createSimpleWorkflowDefinition()
|
2016-11-17 10:10:08 +00:00
|
|
|
{
|
|
|
|
$places = range('a', 'c');
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$transitions = [];
|
2018-12-09 17:01:32 +00:00
|
|
|
$transitionWithMetadataDumpStyle = new Transition('t1', 'a', 'b');
|
|
|
|
$transitions[] = $transitionWithMetadataDumpStyle;
|
|
|
|
$transitionWithMetadataArrowColorPink = new Transition('t2', 'b', 'c');
|
|
|
|
$transitions[] = $transitionWithMetadataArrowColorPink;
|
|
|
|
|
|
|
|
$placesMetadata = [];
|
|
|
|
$placesMetadata['c'] = [
|
|
|
|
'bg_color' => 'DeepSkyBlue',
|
|
|
|
];
|
|
|
|
|
|
|
|
$transitionsMetadata = new \SplObjectStorage();
|
|
|
|
$transitionsMetadata[$transitionWithMetadataDumpStyle] = [
|
|
|
|
'label' => 'My custom transition label 2',
|
|
|
|
'color' => 'Grey',
|
|
|
|
'arrow_color' => 'Purple',
|
|
|
|
];
|
|
|
|
$transitionsMetadata[$transitionWithMetadataArrowColorPink] = [
|
|
|
|
'arrow_color' => 'Pink',
|
|
|
|
];
|
|
|
|
$inMemoryMetadataStore = new InMemoryMetadataStore([], $placesMetadata, $transitionsMetadata);
|
|
|
|
|
|
|
|
return new Definition($places, $transitions, null, $inMemoryMetadataStore);
|
2016-11-21 16:19:45 +00:00
|
|
|
|
|
|
|
// The graph looks like:
|
|
|
|
// +---+ +----+ +---+ +----+ +---+
|
|
|
|
// | a | --> | t1 | --> | b | --> | t2 | --> | c |
|
|
|
|
// +---+ +----+ +---+ +----+ +---+
|
|
|
|
}
|
|
|
|
|
2017-01-13 14:53:55 +00:00
|
|
|
private function createWorkflowWithSameNameTransition()
|
|
|
|
{
|
|
|
|
$places = range('a', 'c');
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$transitions = [];
|
|
|
|
$transitions[] = new Transition('a_to_bc', 'a', ['b', 'c']);
|
2017-01-13 14:53:55 +00:00
|
|
|
$transitions[] = new Transition('b_to_c', 'b', 'c');
|
|
|
|
$transitions[] = new Transition('to_a', 'b', 'a');
|
|
|
|
$transitions[] = new Transition('to_a', 'c', 'a');
|
|
|
|
|
|
|
|
return new Definition($places, $transitions);
|
|
|
|
|
|
|
|
// The graph looks like:
|
|
|
|
// +------------------------------------------------------------+
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// | +----------------------------------------+ |
|
|
|
|
// v | v |
|
|
|
|
// +---+ +---------+ +---+ +--------+ +---+ +------+
|
|
|
|
// | a | --> | a_to_bc | --> | b | --> | b_to_c | --> | c | --> | to_a | -+
|
|
|
|
// +---+ +---------+ +---+ +--------+ +---+ +------+ |
|
|
|
|
// ^ | ^ |
|
|
|
|
// | +----------------------------------+ |
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// +--------------------------------------------------------------------+
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:19:45 +00:00
|
|
|
private function createComplexStateMachineDefinition()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
$places = ['a', 'b', 'c', 'd'];
|
2016-11-21 16:19:45 +00:00
|
|
|
|
|
|
|
$transitions[] = new Transition('t1', 'a', 'b');
|
2018-12-09 17:01:32 +00:00
|
|
|
$transitionWithMetadataDumpStyle = new Transition('t1', 'd', 'b');
|
|
|
|
$transitions[] = $transitionWithMetadataDumpStyle;
|
|
|
|
$transitionWithMetadataArrowColorBlue = new Transition('t2', 'b', 'c');
|
|
|
|
$transitions[] = $transitionWithMetadataArrowColorBlue;
|
2016-11-21 16:19:45 +00:00
|
|
|
$transitions[] = new Transition('t3', 'b', 'd');
|
|
|
|
|
2018-12-09 17:01:32 +00:00
|
|
|
$transitionsMetadata = new \SplObjectStorage();
|
|
|
|
$transitionsMetadata[$transitionWithMetadataDumpStyle] = [
|
|
|
|
'label' => 'My custom transition label 3',
|
|
|
|
'color' => 'Grey',
|
|
|
|
'arrow_color' => 'Red',
|
|
|
|
];
|
|
|
|
$transitionsMetadata[$transitionWithMetadataArrowColorBlue] = [
|
|
|
|
'arrow_color' => 'Blue',
|
|
|
|
];
|
|
|
|
$inMemoryMetadataStore = new InMemoryMetadataStore([], [], $transitionsMetadata);
|
|
|
|
|
|
|
|
return new Definition($places, $transitions, null, $inMemoryMetadataStore);
|
2016-11-21 16:19:45 +00:00
|
|
|
|
|
|
|
// The graph looks like:
|
|
|
|
// t1
|
|
|
|
// +------------------+
|
|
|
|
// v |
|
|
|
|
// +---+ t1 +-----+ t2 +---+ |
|
|
|
|
// | a | ----> | b | ----> | c | |
|
|
|
|
// +---+ +-----+ +---+ |
|
|
|
|
// | |
|
|
|
|
// | t3 |
|
|
|
|
// v |
|
|
|
|
// +-----+ |
|
|
|
|
// | d | -------------+
|
|
|
|
// +-----+
|
2016-11-17 10:10:08 +00:00
|
|
|
}
|
|
|
|
}
|