8000 [Workflow] Added a TransitionException by lyrixx · Pull Request #26651 · symfony/symfony · GitHub
[go: up one dir, main page]

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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Fai 8000 led to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Finished implementation of TransitionException
  • Loading branch information
lyrixx committed Mar 23, 2018
commit 838548c54f9d237d52b81d2fe9a5df3a2ae174a5
8000
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 <lyrixx@lyrixx.info>
*/
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
39 changes: 11 additions & 28 deletions src/Symfony/Component/Workflow/Exception/TransitionException.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,39 @@

namespace Symfony\Component\Workflow\Exception;

use Symfony\Component\Workflow\WorkflowInterface;

/**
* @author Andrew Tch <andrew.tchircoff@gmail.com>
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class TransitionException extends LogicException
{
/**
* @var mixed
*/
private $subject;

/**
* @var string
*/
private $transitionName;
private $workflow;

/**
* @var string
*/
private $workflowName;

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

$this->subject = $subject;
$this->transitionName = $transitionName;
$this->workflowName = $workflowName;

parent::__construct(sprintf('Unable to apply transition "%s" for workflow "%s".', $this->transitionName, $this->workflowName));
$this->workflow = $workflow;
}

/**
* @return mixed
*/
public function getSubject()
{
return $this->subject;
}

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

/**
* @return string
*/
public function getWorkflowName()
public function getWorkflow(): WorkflowInterface
{
return $this->workflowName;
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 <lyrixx@lyrixx.info>
*/
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
0