Merge "Allow false as return type of FileBackendStore::doGetFileXAttributes"
[lhc/web/wiklou.git] / includes / libs / ParamValidator / TypeDef / LimitDef.php
1 <?php
2
3 namespace Wikimedia\ParamValidator\TypeDef;
4
5 /**
6 * Type definition for "limit" types
7 *
8 * A limit type is an integer type that also accepts the magic value "max".
9 * IntegerDef::PARAM_MIN defaults to 0 for this type.
10 *
11 * @see IntegerDef
12 * @since 1.34
13 */
14 class LimitDef extends IntegerDef {
15
16 /**
17 * @inheritDoc
18 *
19 * Additional `$options` accepted:
20 * - 'parse-limit': (bool) Default true, set false to return 'max' rather
21 * than determining the effective value.
22 */
23 public function validate( $name, $value, array $settings, array $options ) {
24 if ( $value === 'max' ) {
25 if ( !isset( $options['parse-limit'] ) || $options['parse-limit'] ) {
26 $value = $this->callbacks->useHighLimits( $options )
27 ? $settings[self::PARAM_MAX2] ?? $settings[self::PARAM_MAX] ?? PHP_INT_MAX
28 : $settings[self::PARAM_MAX] ?? PHP_INT_MAX;
29 }
30 return $value;
31 }
32
33 return parent::validate( $name, $value, $settings, $options );
34 }
35
36 public function normalizeSettings( array $settings ) {
37 $settings += [
38 self::PARAM_MIN => 0,
39 ];
40
41 return parent::normalizeSettings( $settings );
42 }
43
44 }