Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow registry metadata #79

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/WorkflowRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
Expand Down Expand Up @@ -36,9 +37,10 @@ class WorkflowRegistry
protected $dispatcher;

/**
* WorkflowRegistry constructor
* WorkflowRegistry constructor.
*
* @param array $config
*
* @param array $config
* @throws \ReflectionException
*/
public function __construct(array $config)
Expand All @@ -56,10 +58,11 @@ public function __construct(array $config)
}

/**
* Return the $subject workflow
* Return the $subject workflow.
*
* @param object $subject
* @param string $workflowName
*
* @param object $subject
* @param string $workflowName
* @return Workflow
*/
public function get($subject, $workflowName = null)
Expand All @@ -68,7 +71,7 @@ public function get($subject, $workflowName = null)
}

/**
* Add a workflow to the subject
* Add a workflow to the subject.
*
* @param Workflow $workflow
* @param string $supportStrategy
Expand All @@ -79,26 +82,33 @@ public function add(Workflow $workflow, $supportStrategy)
}

/**
* Add a workflow to the registry from array
* Add a workflow to the registry from array.
*
* @param string $name
* @param array $workflowData
*
* @param string $name
* @param array $workflowData
* @throws \ReflectionException
*/
public function addFromArray($name, array $workflowData)
{
$builder = new DefinitionBuilder($workflowData['places']);
$transitionsMetadata = new \SplObjectStorage();

foreach ($workflowData['transitions'] as $transitionName => $transition) {
if (!is_string($transitionName)) {
$transitionName = $transition['name'];
}

foreach ((array)$transition['from'] as $form) {
$builder->addTransition(new Transition($transitionName, $form, $transition['to']));
foreach ((array) $transition['from'] as $form) {
$currentTransition = new Transition($transitionName, $form, $transition['to']);
$builder->addTransition($currentTransition);
if (isset($transition['metadata'])) {
$transitionsMetadata->attach($currentTransition, $transition['metadata']);
}
}
}

$builder->setMetadataStore(new InMemoryMetadataStore([], [], $transitionsMetadata));
$definition = $builder->build();
$markingStore = $this->getMarkingStoreInstance($workflowData);
$workflow = $this->getWorkflowInstance($name, $workflowData, $definition, $markingStore);
Expand All @@ -109,12 +119,13 @@ public function addFromArray($name, array $workflowData)
}

/**
* Return the workflow instance
* Return the workflow instance.
*
* @param string $name
* @param array $workflowData
* @param Definition $definition
* @param MarkingStoreInterface $markingStore
*
* @param String $name
* @param array $workflowData
* @param Definition $definition
* @param MarkingStoreInterface $markingStore
* @return Workflow
*/
protected function getWorkflowInstance(
Expand All @@ -135,11 +146,13 @@ protected function getWorkflowInstance(
}

/**
* Return the making store instance
* Return the making store instance.
*
* @param array $workflowData
*
* @param array $workflowData
* @return MarkingStoreInterface
* @throws \ReflectionException
*
* @return MarkingStoreInterface
*/
protected function getMarkingStoreInstance(array $workflowData)
{
Expand Down