function Week::__construct
Parameters
non-empty-string|null $min:
non-empty-string|null $max:
Overrides Constraint::__construct
File
-
vendor/
symfony/ validator/ Constraints/ Week.php, line 40
Class
- Week
- @author Alexandre Daubois <alex.daubois@gmail.com>
Namespace
Symfony\Component\Validator\ConstraintsCode
public function __construct(?string $min = null, ?string $max = null, string $invalidFormatMessage = 'This value does not represent a valid week in the ISO 8601 format.', string $invalidWeekNumberMessage = 'This value is not a valid week.', string $tooLowMessage = 'This value should not be before week "{{ min }}".', string $tooHighMessage = 'This value should not be after week "{{ max }}".', ?array $groups = null, mixed $payload = null) {
parent::__construct(null, $groups, $payload);
if (null !== $min && !preg_match('/^\\d{4}-W(0[1-9]|[1-4][0-9]|5[0-3])$/', $min)) {
throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min week to be in the ISO 8601 format if set.', __CLASS__));
}
if (null !== $max && !preg_match('/^\\d{4}-W(0[1-9]|[1-4][0-9]|5[0-3])$/', $max)) {
throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the max week to be in the ISO 8601 format if set.', __CLASS__));
}
if (null !== $min && null !== $max) {
[
$minYear,
$minWeekNumber,
] = explode('-W', $min, 2);
[
$maxYear,
$maxWeekNumber,
] = explode('-W', $max, 2);
if ($minYear > $maxYear || $minYear === $maxYear && $minWeekNumber > $maxWeekNumber) {
throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min week to be less than or equal to the max week.', __CLASS__));
}
}
}