getTos example

foreach ($definition->getTransitions() as $i => $transition) {
            $transitionName = $workflowMetadata->getMetadata('label', $transition) ?? $transition->getName();

            foreach ($transition->getFroms() as $from) {
                $dotEdges[] = [
                    'from' => $from,
                    'to' => $transitionName,
                    'direction' => 'from',
                    'transition_number' => $i,
                ];
            }
            foreach ($transition->getTos() as $to) {
                $dotEdges[] = [
                    'from' => $transitionName,
                    'to' => $to,
                    'direction' => 'to',
                    'transition_number' => $i,
                ];
            }
        }

        return $dotEdges;
    }

    
throw new InvalidDefinitionException(sprintf('All transitions for a place must have an unique name. Multiple transitions named "%s" where found for place "%s" in workflow "%s".', $transition->getName()$from$name));
                }
                $places[$from][] = $transition->getName();
            }
        }

        if (!$this->singlePlace) {
            return;
        }

        foreach ($definition->getTransitions() as $transition) {
            if (1 < \count($transition->getTos())) {
                throw new InvalidDefinitionException(sprintf('The marking store of workflow "%s" cannot store many places. But the transition "%s" has too many output (%d). Only one is accepted.', $name$transition->getName(), \count($transition->getTos())));
            }
        }

        $initialPlaces = $definition->getInitialPlaces();
        if (2 <= \count($initialPlaces)) {
            throw new InvalidDefinitionException(sprintf('The marking store of workflow "%s" cannot store many places. But the definition has %d initial places. Only one is supported.', $name, \count($initialPlaces)));
        }
    }
}

        if ($this->isWorkflowTransitionType()) {
            foreach ($definition->getTransitions() as $transition) {
                $transitionEscaped = $this->escape($transition->getName());
                $code[] = "agent $transitionEscaped";
            }
        }
        foreach ($definition->getTransitions() as $transition) {
            $transitionEscaped = $this->escape($transition->getName());
            foreach ($transition->getFroms() as $from) {
                $fromEscaped = $this->escape($from);
                foreach ($transition->getTos() as $to) {
                    $toEscaped = $this->escape($to);

                    $transitionEscapedWithStyle = $this->getTransitionEscapedWithStyle($workflowMetadata$transition$transitionEscaped);

                    $arrowColor = $workflowMetadata->getMetadata('arrow_color', $transition);

                    $transitionColor = '';
                    if (null !== $arrowColor) {
                        $transitionColor = $this->getTransitionColor($arrowColor) ?? '';
                    }

                    
foreach ($definition->getTransitions() as $transitionId => $transition) {
            $transitionMeta = $meta->getTransitionMetadata($transition);

            $transitionLabel = $transition->getName();
            if (\array_key_exists('label', $transitionMeta)) {
                $transitionLabel = $transitionMeta['label'];
            }

            foreach ($transition->getFroms() as $from) {
                $from = $placeNameMap[$from];

                foreach ($transition->getTos() as $to) {
                    $to = $placeNameMap[$to];

                    if (self::TRANSITION_TYPE_STATEMACHINE === $this->transitionType) {
                        $transitionOutput = $this->styleStateMachineTransition($from$to$transitionLabel$transitionMeta);
                    } else {
                        $transitionOutput = $this->styleWorkflowTransition($from$to$transitionId$transitionLabel$transitionMeta);
                    }

                    foreach ($transitionOutput as $line) {
                        if (\in_array($line$output)) {
                            // additional links must be decremented again to align the styling
private function addTransition(Transition $transition): void
    {
        $name = $transition->getName();

        foreach ($transition->getFroms() as $from) {
            if (!isset($this->places[$from])) {
                throw new LogicException(sprintf('Place "%s" referenced in transition "%s" does not exist.', $from$name));
            }
        }

        foreach ($transition->getTos() as $to) {
            if (!isset($this->places[$to])) {
                throw new LogicException(sprintf('Place "%s" referenced in transition "%s" does not exist.', $to$name));
            }
        }

        $this->transitions[] = $transition;
    }
}

    public function onTransition(Event $event)
    {
        $this->logger->info(sprintf('Transition "%s" for subject of class "%s" in workflow "%s".', $event->getTransition()->getName()$event->getSubject()::class$event->getWorkflowName()));
    }

    /** * @return void */
    public function onEnter(Event $event)
    {
        foreach ($event->getTransition()->getTos() as $place) {
            $this->logger->info(sprintf('Entering "%s" for subject of class "%s" in workflow "%s".', $place$event->getSubject()::class$event->getWorkflowName()));
        }
    }

    public static function getSubscribedEvents(): array
    {
        return [
            'workflow.leave' => ['onLeave'],
            'workflow.transition' => ['onTransition'],
            'workflow.enter' => ['onEnter'],
        ];
    }
$labelColor = $workflowMetadata->getMetadata('color', $transition);
            if (null !== $labelColor) {
                $attributes['fontcolor'] = $labelColor;
            }
            $arrowColor = $workflowMetadata->getMetadata('arrow_color', $transition);
            if (null !== $arrowColor) {
                $attributes['color'] = $arrowColor;
            }

            foreach ($transition->getFroms() as $from) {
                foreach ($transition->getTos() as $to) {
                    $edge = [
                        'name' => $transitionName,
                        'to' => $to,
                        'attributes' => $attributes,
                    ];
                    $edges[$from][] = $edge;
                }
            }
        }

        return $edges;
    }
$event = new TransitionEvent($subject$marking$transition$this$context);

        $this->dispatcher->dispatch($event, WorkflowEvents::TRANSITION);
        $this->dispatcher->dispatch($eventsprintf('workflow.%s.transition', $this->name));
        $this->dispatcher->dispatch($eventsprintf('workflow.%s.transition.%s', $this->name, $transition->getName()));

        return $event->getContext();
    }

    private function enter(object $subject, Transition $transition, Marking $marking, array $context): void
    {
        $places = $transition->getTos();

        if ($this->shouldDispatchEvent(WorkflowEvents::ENTER, $context)) {
            $event = new EnterEvent($subject$marking$transition$this$context);

            $this->dispatcher->dispatch($event, WorkflowEvents::ENTER);
            $this->dispatcher->dispatch($eventsprintf('workflow.%s.enter', $this->name));

            foreach ($places as $place) {
                $this->dispatcher->dispatch($eventsprintf('workflow.%s.enter.%s', $this->name, $place));
            }
        }

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\Workflow\Transition;

class TransitionTest extends TestCase
{
    public function testConstructor()
    {
        $transition = new Transition('name', 'a', 'b');

        $this->assertSame('name', $transition->getName());
        $this->assertSame(['a']$transition->getFroms());
        $this->assertSame(['b']$transition->getTos());
    }
}

class StateMachineValidator implements DefinitionValidatorInterface
{
    /** * @return void */
    public function validate(Definition $definition, string $name)
    {
        $transitionFromNames = [];
        foreach ($definition->getTransitions() as $transition) {
            // Make sure that each transition has exactly one TO             if (1 !== \count($transition->getTos())) {
                throw new InvalidDefinitionException(sprintf('A transition in StateMachine can only have one output. But the transition "%s" in StateMachine "%s" has %d outputs.', $transition->getName()$name, \count($transition->getTos())));
            }

            // Make sure that each transition has exactly one FROM             $froms = $transition->getFroms();
            if (1 !== \count($froms)) {
                throw new InvalidDefinitionException(sprintf('A transition in StateMachine can only have one input. But the transition "%s" in StateMachine "%s" has %d inputs.', $transition->getName()$name, \count($froms)));
            }

            // Enforcing uniqueness of the names of transitions starting at each node             $from = reset($froms);
            
Home | Imprint | This part of the site doesn't use cookies.