Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Workflow] Added a TransitionException #26651

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

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
namespace Symfony\Component\Workflow\Exception;

use Symfony\Component\Workflow\TransitionBlockerList;
use Symfony\Component\Workflow\WorkflowInterface;

/**
* Thrown by Workflow when a not enabled transition is applied on a subject.
*
* @author Grégoire Pineau <[email protected]>
*/
class NotEnabledTransitionException extends LogicException
class NotEnabledTransitionException extends TransitionException
{
private $transitionBlockerList;

public function __construct(string $transitionName, string $workflowName, TransitionBlockerList $transitionBlockerList)
public function __construct($subject, string $transitionName, WorkflowInterface $workflow, TransitionBlockerList $transitionBlockerList)
{
parent::__construct(sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflowName));
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflow->getName()));

$this->transitionBlockerList = $transitionBlockerList;
}
Expand Down
49 changes: 49 additions & 0 deletions src/Symfony/Component/Workflow/Exception/TransitionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Workflow\Exception;

use Symfony\Component\Workflow\WorkflowInterface;

/**
* @author Andrew Tch <[email protected]>
* @author Grégoire Pineau <[email protected]>
*/
class TransitionException extends LogicException
{
private $subject;
private $transitionName;
private $workflow;

public function __construct($subject, string $transitionName, WorkflowInterface $workflow, string $message)
{
parent::__construct($message);

$this->subject = $subject;
$this->transitionName = $transitionName;
$this->workflow = $workflow;
}

public function getSubject()
{
return $this->subject;
}

public function getTransitionName(): string
{
return $this->transitionName;
}

public function getWorkflow(): WorkflowInterface
{
return $this->workflow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@

namespace Symfony\Component\Workflow\Exception;

use Symfony\Component\Workflow\WorkflowInterface;

/**
* Thrown by Workflow when an undefined transition is applied on a subject.
*
* @author Grégoire Pineau <[email protected]>
*/
class UndefinedTransitionException extends LogicException
class UndefinedTransitionException extends TransitionException
{
public function __construct(string $transitionName, string $workflowName)
public function __construct($subject, string $transitionName, WorkflowInterface $workflow)
{
parent::__construct(sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflowName));
parent::__construct($subject, $transitionName, $workflow, sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflow->getName()));
}
}
3 changes: 3 additions & 0 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ public function testApplyWithNotEnabledTransition()
$this->assertCount(1, $e->getTransitionBlockerList());
$list = iterator_to_array($e->getTransitionBlockerList());
$this->assertSame('The marking does not enable the transition.', $list[0]->getMessage());
$this->assertSame($e->getWorkflow(), $workflow);
$this->assertSame($e->getSubject(), $subject);
$this->assertSame($e->getTransitionName(), 't2');
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function buildTransitionBlockerList($subject, string $transitionName): Tr
}

if (!$transitionBlockerList) {
throw new UndefinedTransitionException($transitionName, $this->name);
throw new UndefinedTransitionException($subject, $transitionName, $this);
}

return $transitionBlockerList;
Expand Down Expand Up @@ -168,11 +168,11 @@ public function apply($subject, $transitionName)
}

if (!$transitionBlockerList) {
throw new UndefinedTransitionException($transitionName, $this->name);
throw new UndefinedTransitionException($subject, $transitionName, $this);
}

if (!$applied) {
throw new NotEnabledTransitionException($transitionName, $this->name, $transitionBlockerList);
throw new NotEnabledTransitionException($subject, $transitionName, $this, $transitionBlockerList);
}

return $marking;
Expand Down