5use InvalidArgumentException;
10use Wikimedia\Timestamp\ConvertibleTimestamp;
20 public const INFINITY_VALS = [
'infinite',
'indefinite',
'infinity',
'never' ];
35 public function validate( $name, $value, array $settings, array $options ) {
38 }
catch ( InvalidArgumentException $e ) {
39 $this->
failure(
'badexpiry', $name, $value, $settings, $options );
42 if ( $expiry !==
'infinity' && $expiry < ConvertibleTimestamp::now( TS_ISO_8601 ) ) {
43 $this->
failure(
'badexpiry-past', $name, $value, $settings, $options );
48 if ( self::expiryExceedsMax( $expiry, $max ) ) {
49 $dontUseMax = empty( $settings[self::PARAM_USE_MAX] );
51 $msg = DataMessageValue::new(
53 ?
'paramvalidator-badexpiry-duration'
54 :
'paramvalidator-badexpiry-duration-max',
57 $this->
failure( $msg, $name, $value, $settings, $options, $dontUseMax );
65 public function getHelpInfo( $name, array $settings, array $options ) {
66 $info = parent::getHelpInfo( $name, $settings, $options );
73 array_map(
static function ( $val ) {
75 }, self::INFINITY_VALS )
92 public static function normalizeExpiry( ?
string $expiry =
null, ?
int $style =
null ) {
93 if ( $expiry ===
null ) {
96 if ( in_array( $expiry, self::INFINITY_VALS,
true ) ) {
101 $unix = strtotime( $expiry, ConvertibleTimestamp::time() );
102 if ( $unix ===
false ) {
104 throw new InvalidArgumentException(
"Invalid expiry value: {$expiry}" );
110 $expiryConvertibleTimestamp =
new ConvertibleTimestamp( $unix === 0 ?
'00' : $unix );
112 if ( $style !==
null ) {
113 return $expiryConvertibleTimestamp->getTimestamp( $style );
116 return $expiryConvertibleTimestamp;
129 if ( self::expiryExceedsMax( $expiry, $maxExpiryDuration ) ) {
146 if ( !$max || !$expiry || $expiry ===
'infinity' ) {
151 return $expiry > $max;