forked from nucleos/nucleos-form-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateAfter.php
More file actions
116 lines (99 loc) · 2.93 KB
/
Copy pathDateAfter.php
File metadata and controls
116 lines (99 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
/*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nucleos\Form\Validator\Constraints;
use Attribute;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\InvalidOptionsException;
use Symfony\Component\Validator\Exception\MissingOptionsException;
/**
* @Annotation
* @Target({"CLASS", "ANNOTATION"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class DateAfter extends Constraint
{
/**
* @var string
*/
public $firstField;
/**
* @var string
*/
public $secondField;
/**
* @var string
*/
public $message = 'error.second_date_before_first';
/**
* @var string
*/
public $emptyMessage = 'error.date_part_empty';
/**
* @var bool
*/
public $required = true;
/**
* @SuppressWarnings("PHPMD.NPathComplexity")
*
* @param array<string, mixed> $options
*/
public function __construct(
array $options = [],
?string $firstField = null,
?string $secondField = null,
?string $message = null,
?string $emptyMessage = null,
?bool $required = null,
?array $groups = null,
mixed $payload = null,
) {
if (null !== $firstField) {
$options['firstField'] = $firstField;
}
if (null !== $secondField) {
$options['secondField'] = $secondField;
}
parent::__construct($options, $groups, $payload);
$this->firstField = $firstField ?? $this->firstField;
$this->secondField = $secondField ?? $this->secondField;
$this->message = $message ?? $this->message;
$this->emptyMessage = $emptyMessage ?? $this->emptyMessage;
$this->required = $required ?? $this->required;
if (null === $this->firstField) {
throw new MissingOptionsException('The options "firstField" must be set for constraint "'.__CLASS__.'".', [
'firstField',
]);
}
if (null === $this->secondField) {
throw new MissingOptionsException('The options "secondField" must be set for constraint "'.__CLASS__.'".', [
'secondField',
]);
}
if ($this->firstField === $this->secondField) {
throw new InvalidOptionsException('The options "firstField" and "secondField" can not be the same for constraint '.__CLASS__, [
'firstField',
'secondField',
]);
}
}
/**
* @return string[]
*/
public function getRequiredOptions(): array
{
return [
'firstField',
'secondField',
];
}
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}