|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace TemplateNamespace\Validation\Constraints; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Validator\Constraint; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* This is a template Entity constraint. |
|
9
|
|
|
* |
|
10
|
|
|
* The Constraint does very little other than specify a message and imply a |
|
11
|
|
|
* ConstraintValidator with the same FQN as this class, but with `Validator` appended. |
|
12
|
|
|
* |
|
13
|
|
|
* @see https://symfony.com/doc/2.6/cookbook/validation/custom_constraint.html |
|
14
|
|
|
* |
|
15
|
|
|
* Suggest using the `./bin/doctrine dsm:override:create` command to create a new |
|
16
|
|
|
* override straight after you generate the file. |
|
17
|
|
|
* |
|
18
|
|
|
* Then you can edit it and update your override as required using |
|
19
|
|
|
* `./bin/doctrine dsm:overrides:update -a fromProject` |
|
20
|
|
|
* |
|
21
|
|
|
* And then reapply after a new build using |
|
22
|
|
|
* `./bin/doctrine dsm:overrides:update -a toProject` |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
class TemplateEntityIsValidConstraint extends Constraint |
|
26
|
|
|
{ |
|
27
|
|
|
public const VALUE_TYPE = 'TemplateEntity'; |
|
28
|
|
|
|
|
29
|
|
|
public const MESSAGE = 'The value {{ string }} is not a valid ' . self::VALUE_TYPE; |
|
30
|
|
|
|
|
31
|
|
|
public $message = self::MESSAGE; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns whether the constraint can be put onto classes, properties or |
|
36
|
|
|
* both. |
|
37
|
|
|
* |
|
38
|
|
|
* This method should return one or more of the constants |
|
39
|
|
|
* self::CLASS_CONSTRAINT and self::PROPERTY_CONSTRAINT. |
|
40
|
|
|
* |
|
41
|
|
|
* @return string|array One or more constant values |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getTargets(): string |
|
44
|
|
|
{ |
|
45
|
|
|
return self::CLASS_CONSTRAINT; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function validatedBy(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return TemplateEntityIsValidConstraintValidator::class; |
|
51
|
|
|
} |
|
52
|
|
|
} |