mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
validation: no more workflow without dest
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Workflow\Validator;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
class StepDestValid extends Constraint
|
||||
{
|
||||
public string $messageDestNotAllowed = 'workflow.As the step is final, no dest are allowed';
|
||||
|
||||
public string $messageRequireDest = 'workflow.As the step is not final, dest are required';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return [self::CLASS_CONSTRAINT];
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Workflow\Validator;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
||||
use function count;
|
||||
|
||||
class StepDestValidValidator extends ConstraintValidator
|
||||
{
|
||||
/**
|
||||
* @param EntityWorkflowStep $value
|
||||
* @param Constraint|StepDestValid $constraint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$constraint instanceof StepDestValid) {
|
||||
throw new UnexpectedTypeException($constraint, StepDestValid::class);
|
||||
}
|
||||
|
||||
if (!$value instanceof EntityWorkflowStep) {
|
||||
throw new UnexpectedValueException($value, EntityWorkflowStep::class);
|
||||
}
|
||||
|
||||
if ($value->isFinal() && 0 < count($value->getDestUser())) {
|
||||
$this->context->buildViolation($constraint->messageDestNotAllowed)
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if (!$value->isFinal() && 0 === count($value->getDestUser())) {
|
||||
$this->context->buildViolation($constraint->messageRequireDest)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user