Last active
March 20, 2020 07:40
-
-
Save xabbuh/ac96bb561edd7f6dbc1c22cccd0b6816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Validator; | |
use Symfony\Component\Validator\Constraints\Range; | |
use Symfony\Component\Validator\Constraints\RangeValidator; | |
class YearRange extends Range | |
{ | |
public function __construct($options) | |
{ | |
$options['max'] = date('Y'); | |
parent::__construct($options); | |
} | |
public function validatedBy(): string | |
{ | |
return RangeValidator::class; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I extended this a bit, to always allow the current year as
max
: