This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Workflow/TransitionBlocker.php

92 lines
2.8 KiB
PHP
Raw Normal View History

2017-10-29 17:58:58 +00:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Workflow;
/**
* A reason why a transition cannot be performed for a subject.
*/
final class TransitionBlocker
2017-10-29 17:58:58 +00:00
{
const BLOCKED_BY_MARKING = '19beefc8-6b1e-4716-9d07-a39bd6d16e34';
const BLOCKED_BY_EXPRESSION_GUARD_LISTENER = '326a1e9c-0c12-11e8-ba89-0ed5f89f718b';
const UNKNOWN = 'e8b5bbb9-5913-4b98-bfa6-65dbd228a82a';
2017-10-29 17:58:58 +00:00
private $message;
private $code;
private $parameters;
2017-10-29 17:58:58 +00:00
/**
* @param string $code Code is a machine-readable string, usually an UUID
* @param array $parameters This is useful if you would like to pass around the condition values, that
* blocked the transition. E.g. for a condition "distance must be larger than
* 5 miles", you might want to pass around the value of 5.
2017-10-29 17:58:58 +00:00
*/
public function __construct(string $message, string $code, array $parameters = array())
{
$this->message = $message;
$this->code = $code;
$this->parameters = $parameters;
}
/**
* Create a blocker that says the transition cannot be made because it is
* not enabled.
2017-10-29 17:58:58 +00:00
*
* It means the subject is in wrong place (i.e. status):
* * If the workflow is a state machine: the subject is not in the previous place of the transition.
* * If the workflow is a workflow: the subject is not in all previous places of the transition.
2017-10-29 17:58:58 +00:00
*/
public static function createBlockedByMarking(Marking $marking): self
2017-10-29 17:58:58 +00:00
{
return new static('The marking does not enable the transition.', self::BLOCKED_BY_MARKING, array(
'marking' => $marking,
));
2017-10-29 17:58:58 +00:00
}
/**
* Creates a blocker that says the transition cannot be made because it has
* been blocked by the expression guard listener.
2017-10-29 17:58:58 +00:00
*/
public static function createBlockedByExpressionGuardListener(string $expression): self
2017-10-29 17:58:58 +00:00
{
return new static('The expression blocks the transition.', self::BLOCKED_BY_EXPRESSION_GUARD_LISTENER, array(
'expression' => $expression,
));
2017-10-29 17:58:58 +00:00
}
/**
* Creates a blocker that says the transition cannot be made because of an
* unknown reason.
2017-10-29 17:58:58 +00:00
*
* This blocker code is chiefly for preserving backwards compatibility.
*/
public static function createUnknown(): self
2017-10-29 17:58:58 +00:00
{
return new static('Unknown reason.', self::UNKNOWN);
2017-10-29 17:58:58 +00:00
}
public function getMessage(): string
{
return $this->message;
}
public function getCode(): string
{
return $this->code;
}
public function getParameters(): array
{
return $this->parameters;
}
}