MediaWiki  master
ParamValidator.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use DomainException;
6 use InvalidArgumentException;
7 use Wikimedia\Assert\Assert;
12 use Wikimedia\ObjectFactory;
13 
43 
68  public const PARAM_DEFAULT = 'param-default';
69 
76  public const PARAM_TYPE = 'param-type';
77 
84  public const PARAM_REQUIRED = 'param-required';
85 
112  public const PARAM_ISMULTI = 'param-ismulti';
113 
119  public const PARAM_ISMULTI_LIMIT1 = 'param-ismulti-limit1';
120 
127  public const PARAM_ISMULTI_LIMIT2 = 'param-ismulti-limit2';
128 
137  public const PARAM_ALL = 'param-all';
138 
145  public const PARAM_ALLOW_DUPLICATES = 'param-allow-duplicates';
146 
153  public const PARAM_SENSITIVE = 'param-sensitive';
154 
161  public const PARAM_DEPRECATED = 'param-deprecated';
162 
168  public const PARAM_IGNORE_UNRECOGNIZED_VALUES = 'param-ignore-unrecognized-values';
169 
173  public const ALL_DEFAULT_STRING = '*';
174 
176  public static $STANDARD_TYPES = [
177  'boolean' => [ 'class' => TypeDef\BooleanDef::class ],
178  'checkbox' => [ 'class' => TypeDef\PresenceBooleanDef::class ],
179  'integer' => [ 'class' => TypeDef\IntegerDef::class ],
180  'limit' => [ 'class' => TypeDef\LimitDef::class ],
181  'float' => [ 'class' => TypeDef\FloatDef::class ],
182  'double' => [ 'class' => TypeDef\FloatDef::class ],
183  'string' => [ 'class' => TypeDef\StringDef::class ],
184  'password' => [ 'class' => TypeDef\PasswordDef::class ],
185  'NULL' => [
186  'class' => TypeDef\StringDef::class,
187  'args' => [ [
188  'allowEmptyWhenRequired' => true,
189  ] ],
190  ],
191  'timestamp' => [ 'class' => TypeDef\TimestampDef::class ],
192  'upload' => [ 'class' => TypeDef\UploadDef::class ],
193  'enum' => [ 'class' => TypeDef\EnumDef::class ],
194  'expiry' => [ 'class' => TypeDef\ExpiryDef::class ],
195  ];
196 
198  private $callbacks;
199 
201  private $objectFactory;
202 
204  private $typeDefs = [];
205 
207  private $ismultiLimit1;
208 
210  private $ismultiLimit2;
211 
221  public function __construct(
223  ObjectFactory $objectFactory,
224  array $options = []
225  ) {
226  $this->callbacks = $callbacks;
227  $this->objectFactory = $objectFactory;
228 
229  $this->addTypeDefs( $options['typeDefs'] ?? self::$STANDARD_TYPES );
230  $this->ismultiLimit1 = $options['ismultiLimits'][0] ?? 50;
231  $this->ismultiLimit2 = $options['ismultiLimits'][1] ?? 500;
232  }
233 
238  public function knownTypes() {
239  return array_keys( $this->typeDefs );
240  }
241 
248  public function addTypeDefs( array $typeDefs ) {
249  foreach ( $typeDefs as $name => $def ) {
250  $this->addTypeDef( $name, $def );
251  }
252  }
253 
267  public function addTypeDef( $name, $typeDef ) {
268  Assert::parameterType(
269  implode( '|', [ TypeDef::class, 'array' ] ),
270  $typeDef,
271  '$typeDef'
272  );
273 
274  if ( isset( $this->typeDefs[$name] ) ) {
275  throw new InvalidArgumentException( "Type '$name' is already registered" );
276  }
277  $this->typeDefs[$name] = $typeDef;
278  }
279 
286  public function overrideTypeDef( $name, $typeDef ) {
287  Assert::parameterType(
288  implode( '|', [ TypeDef::class, 'array', 'null' ] ),
289  $typeDef,
290  '$typeDef'
291  );
292 
293  if ( $typeDef === null ) {
294  unset( $this->typeDefs[$name] );
295  } else {
296  $this->typeDefs[$name] = $typeDef;
297  }
298  }
299 
305  public function hasTypeDef( $name ) {
306  return isset( $this->typeDefs[$name] );
307  }
308 
314  public function getTypeDef( $type ) {
315  if ( is_array( $type ) ) {
316  $type = 'enum';
317  }
318 
319  if ( !isset( $this->typeDefs[$type] ) ) {
320  return null;
321  }
322 
323  $def = $this->typeDefs[$type];
324  if ( !$def instanceof TypeDef ) {
325  $def = $this->objectFactory->createObject( $def, [
326  'extraArgs' => [ $this->callbacks ],
327  'assertClass' => TypeDef::class,
328  ] );
329  $this->typeDefs[$type] = $def;
330  }
331 
332  return $def;
333  }
334 
340  private function normalizeSettingsInternal( $settings ) {
341  // Shorthand
342  if ( !is_array( $settings ) ) {
343  $settings = [
344  self::PARAM_DEFAULT => $settings,
345  ];
346  }
347 
348  // When type is not given, determine it from the type of the PARAM_DEFAULT
349  if ( !isset( $settings[self::PARAM_TYPE] ) ) {
350  $settings[self::PARAM_TYPE] = gettype( $settings[self::PARAM_DEFAULT] ?? null );
351  }
352 
353  return $settings;
354  }
355 
362  public function normalizeSettings( $settings ) {
363  $settings = $this->normalizeSettingsInternal( $settings );
364 
365  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
366  if ( $typeDef ) {
367  $settings = $typeDef->normalizeSettings( $settings );
368  }
369 
370  return $settings;
371  }
372 
391  public function checkSettings( string $name, $settings, array $options ) : array {
392  $settings = $this->normalizeSettingsInternal( $settings );
393  $issues = [];
394  $allowedKeys = [
397  ];
398  $messages = [];
399 
400  $type = $settings[self::PARAM_TYPE];
401  $typeDef = null;
402  if ( !is_string( $type ) && !is_array( $type ) ) {
403  $issues[self::PARAM_TYPE] = 'PARAM_TYPE must be a string or array, got ' . gettype( $type );
404  } else {
405  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
406  if ( !$typeDef ) {
407  if ( is_array( $type ) ) {
408  $type = 'enum';
409  }
410  $issues[self::PARAM_TYPE] = "Unknown/unregistered PARAM_TYPE \"$type\"";
411  }
412  }
413 
414  if ( isset( $settings[self::PARAM_DEFAULT] ) ) {
415  try {
416  $this->validateValue(
417  $name, $settings[self::PARAM_DEFAULT], $settings, [ 'is-default' => true ] + $options
418  );
419  } catch ( ValidationException $ex ) {
420  $issues[self::PARAM_DEFAULT] = 'Value for PARAM_DEFAULT does not validate (code '
421  . $ex->getFailureMessage()->getCode() . ')';
422  }
423  }
424 
425  if ( !is_bool( $settings[self::PARAM_REQUIRED] ?? false ) ) {
426  $issues[self::PARAM_REQUIRED] = 'PARAM_REQUIRED must be boolean, got '
427  . gettype( $settings[self::PARAM_REQUIRED] );
428  }
429 
430  if ( !is_bool( $settings[self::PARAM_ISMULTI] ?? false ) ) {
431  $issues[self::PARAM_ISMULTI] = 'PARAM_ISMULTI must be boolean, got '
432  . gettype( $settings[self::PARAM_ISMULTI] );
433  }
434 
435  if ( !empty( $settings[self::PARAM_ISMULTI] ) ) {
436  $allowedKeys = array_merge( $allowedKeys, [
437  self::PARAM_ISMULTI_LIMIT1, self::PARAM_ISMULTI_LIMIT2,
438  self::PARAM_ALL, self::PARAM_ALLOW_DUPLICATES
439  ] );
440 
441  $limit1 = $settings[self::PARAM_ISMULTI_LIMIT1] ?? $this->ismultiLimit1;
442  $limit2 = $settings[self::PARAM_ISMULTI_LIMIT2] ?? $this->ismultiLimit2;
443  if ( !is_int( $limit1 ) ) {
444  $issues[self::PARAM_ISMULTI_LIMIT1] = 'PARAM_ISMULTI_LIMIT1 must be an integer, got '
445  . gettype( $settings[self::PARAM_ISMULTI_LIMIT1] );
446  } elseif ( $limit1 <= 0 ) {
447  $issues[self::PARAM_ISMULTI_LIMIT1] =
448  "PARAM_ISMULTI_LIMIT1 must be greater than 0, got $limit1";
449  }
450  if ( !is_int( $limit2 ) ) {
451  $issues[self::PARAM_ISMULTI_LIMIT2] = 'PARAM_ISMULTI_LIMIT2 must be an integer, got '
452  . gettype( $settings[self::PARAM_ISMULTI_LIMIT2] );
453  } elseif ( $limit2 < $limit1 ) {
454  $issues[self::PARAM_ISMULTI_LIMIT2] =
455  'PARAM_ISMULTI_LIMIT2 must be greater than or equal to PARAM_ISMULTI_LIMIT1, but '
456  . "$limit2 < $limit1";
457  }
458 
459  $all = $settings[self::PARAM_ALL] ?? false;
460  if ( !is_string( $all ) && !is_bool( $all ) ) {
461  $issues[self::PARAM_ALL] = 'PARAM_ALL must be a string or boolean, got ' . gettype( $all );
462  } elseif ( $all !== false && $typeDef ) {
463  if ( $all === true ) {
465  }
466  $values = $typeDef->getEnumValues( $name, $settings, $options );
467  if ( !is_array( $values ) ) {
468  $issues[self::PARAM_ALL] = 'PARAM_ALL cannot be used with non-enumerated types';
469  } elseif ( in_array( $all, $values, true ) ) {
470  $issues[self::PARAM_ALL] = 'Value for PARAM_ALL conflicts with an enumerated value';
471  }
472  }
473 
474  if ( !is_bool( $settings[self::PARAM_ALLOW_DUPLICATES] ?? false ) ) {
475  $issues[self::PARAM_ALLOW_DUPLICATES] = 'PARAM_ALLOW_DUPLICATES must be boolean, got '
476  . gettype( $settings[self::PARAM_ALLOW_DUPLICATES] );
477  }
478  }
479 
480  if ( !is_bool( $settings[self::PARAM_SENSITIVE] ?? false ) ) {
481  $issues[self::PARAM_SENSITIVE] = 'PARAM_SENSITIVE must be boolean, got '
482  . gettype( $settings[self::PARAM_SENSITIVE] );
483  }
484 
485  if ( !is_bool( $settings[self::PARAM_DEPRECATED] ?? false ) ) {
486  $issues[self::PARAM_DEPRECATED] = 'PARAM_DEPRECATED must be boolean, got '
487  . gettype( $settings[self::PARAM_DEPRECATED] );
488  }
489 
490  if ( !is_bool( $settings[self::PARAM_IGNORE_UNRECOGNIZED_VALUES] ?? false ) ) {
491  $issues[self::PARAM_IGNORE_UNRECOGNIZED_VALUES] = 'PARAM_IGNORE_UNRECOGNIZED_VALUES must be '
492  . 'boolean, got ' . gettype( $settings[self::PARAM_IGNORE_UNRECOGNIZED_VALUES] );
493  }
494 
495  $ret = [ 'issues' => $issues, 'allowedKeys' => $allowedKeys, 'messages' => $messages ];
496  if ( $typeDef ) {
497  $ret = $typeDef->checkSettings( $name, $settings, $options, $ret );
498  }
499 
500  return $ret;
501  }
502 
514  public function getValue( $name, $settings, array $options = [] ) {
515  $settings = $this->normalizeSettings( $settings );
516 
517  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
518  if ( !$typeDef ) {
519  throw new DomainException(
520  "Param $name's type is unknown - {$settings[self::PARAM_TYPE]}"
521  );
522  }
523 
524  $value = $typeDef->getValue( $name, $settings, $options );
525 
526  if ( $value !== null ) {
527  if ( !empty( $settings[self::PARAM_SENSITIVE] ) ) {
528  $strValue = $typeDef->stringifyValue( $name, $value, $settings, $options );
529  $this->callbacks->recordCondition(
530  DataMessageValue::new( 'paramvalidator-param-sensitive', [], 'param-sensitive' )
531  ->plaintextParams( $name, $strValue ),
532  $name, $value, $settings, $options
533  );
534  }
535 
536  // Set a warning if a deprecated parameter has been passed
537  if ( !empty( $settings[self::PARAM_DEPRECATED] ) ) {
538  $strValue = $typeDef->stringifyValue( $name, $value, $settings, $options );
539  $this->callbacks->recordCondition(
540  DataMessageValue::new( 'paramvalidator-param-deprecated', [], 'param-deprecated' )
541  ->plaintextParams( $name, $strValue ),
542  $name, $value, $settings, $options
543  );
544  }
545  } elseif ( isset( $settings[self::PARAM_DEFAULT] ) ) {
546  $value = $settings[self::PARAM_DEFAULT];
547  $options['is-default'] = true;
548  }
549 
550  return $this->validateValue( $name, $value, $settings, $options );
551  }
552 
566  public function validateValue( $name, $value, $settings, array $options = [] ) {
567  $settings = $this->normalizeSettings( $settings );
568 
569  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
570  if ( !$typeDef ) {
571  throw new DomainException(
572  "Param $name's type is unknown - {$settings[self::PARAM_TYPE]}"
573  );
574  }
575 
576  if ( $value === null ) {
577  if ( !empty( $settings[self::PARAM_REQUIRED] ) ) {
578  throw new ValidationException(
579  DataMessageValue::new( 'paramvalidator-missingparam', [], 'missingparam' )
580  ->plaintextParams( $name ),
581  $name, $value, $settings
582  );
583  }
584  return null;
585  }
586 
587  // Non-multi
588  if ( empty( $settings[self::PARAM_ISMULTI] ) ) {
589  if ( is_string( $value ) && substr( $value, 0, 1 ) === "\x1f" ) {
590  throw new ValidationException(
591  DataMessageValue::new( 'paramvalidator-notmulti', [], 'badvalue' )
592  ->plaintextParams( $name, $value ),
593  $name, $value, $settings
594  );
595  }
596  return $typeDef->validate( $name, $value, $settings, $options );
597  }
598 
599  // Split the multi-value and validate each parameter
600  $limit1 = $settings[self::PARAM_ISMULTI_LIMIT1] ?? $this->ismultiLimit1;
601  $limit2 = max( $limit1, $settings[self::PARAM_ISMULTI_LIMIT2] ?? $this->ismultiLimit2 );
602  $valuesList = is_array( $value ) ? $value : self::explodeMultiValue( $value, $limit2 + 1 );
603 
604  // Handle PARAM_ALL
605  $enumValues = $typeDef->getEnumValues( $name, $settings, $options );
606  if ( is_array( $enumValues ) && isset( $settings[self::PARAM_ALL] ) &&
607  count( $valuesList ) === 1
608  ) {
609  $allValue = is_string( $settings[self::PARAM_ALL] )
610  ? $settings[self::PARAM_ALL]
612  if ( $valuesList[0] === $allValue ) {
613  return $enumValues;
614  }
615  }
616 
617  // Avoid checking useHighLimits() unless it's actually necessary
618  $sizeLimit = (
619  $limit2 > $limit1 && count( $valuesList ) > $limit1 &&
620  $this->callbacks->useHighLimits( $options )
621  ) ? $limit2 : $limit1;
622  if ( count( $valuesList ) > $sizeLimit ) {
623  throw new ValidationException(
624  DataMessageValue::new( 'paramvalidator-toomanyvalues', [], 'toomanyvalues', [
625  'limit' => $sizeLimit,
626  'lowlimit' => $limit1,
627  'highlimit' => $limit2,
628  ] )->plaintextParams( $name )->numParams( $sizeLimit ),
629  $name, $valuesList, $settings
630  );
631  }
632 
633  $options['values-list'] = $valuesList;
634  $validValues = [];
635  $invalidValues = [];
636  foreach ( $valuesList as $v ) {
637  try {
638  $validValues[] = $typeDef->validate( $name, $v, $settings, $options );
639  } catch ( ValidationException $ex ) {
640  if ( $ex->getFailureMessage()->getCode() !== 'badvalue' ||
641  empty( $settings[self::PARAM_IGNORE_UNRECOGNIZED_VALUES] )
642  ) {
643  throw $ex;
644  }
645  $invalidValues[] = $v;
646  }
647  }
648  if ( $invalidValues ) {
649  if ( is_array( $value ) ) {
650  $value = self::implodeMultiValue( $value );
651  }
652  $this->callbacks->recordCondition(
653  DataMessageValue::new( 'paramvalidator-unrecognizedvalues', [], 'unrecognizedvalues', [
654  'values' => $invalidValues,
655  ] )
656  ->plaintextParams( $name, $value )
657  ->commaListParams( array_map( function ( $v ) {
658  return new ScalarParam( ParamType::PLAINTEXT, $v );
659  }, $invalidValues ) )
660  ->numParams( count( $invalidValues ) ),
661  $name, $value, $settings, $options
662  );
663  }
664 
665  // Throw out duplicates if requested
666  if ( empty( $settings[self::PARAM_ALLOW_DUPLICATES] ) ) {
667  $validValues = array_values( array_unique( $validValues ) );
668  }
669 
670  return $validValues;
671  }
672 
682  public function getParamInfo( $name, $settings, array $options ) {
683  $settings = $this->normalizeSettings( $settings );
684  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
685  $info = [];
686 
687  $info['type'] = $settings[self::PARAM_TYPE];
688  $info['required'] = !empty( $settings[self::PARAM_REQUIRED] );
689  if ( !empty( $settings[self::PARAM_DEPRECATED] ) ) {
690  $info['deprecated'] = true;
691  }
692  if ( !empty( $settings[self::PARAM_SENSITIVE] ) ) {
693  $info['sensitive'] = true;
694  }
695  if ( isset( $settings[self::PARAM_DEFAULT] ) ) {
696  $info['default'] = $settings[self::PARAM_DEFAULT];
697  }
698  $info['multi'] = !empty( $settings[self::PARAM_ISMULTI] );
699  if ( $info['multi'] ) {
700  $info['lowlimit'] = $settings[self::PARAM_ISMULTI_LIMIT1] ?? $this->ismultiLimit1;
701  $info['highlimit'] = max(
702  $info['lowlimit'], $settings[self::PARAM_ISMULTI_LIMIT2] ?? $this->ismultiLimit2
703  );
704  $info['limit'] =
705  $info['highlimit'] > $info['lowlimit'] && $this->callbacks->useHighLimits( $options )
706  ? $info['highlimit']
707  : $info['lowlimit'];
708 
709  if ( !empty( $settings[self::PARAM_ALLOW_DUPLICATES] ) ) {
710  $info['allowsduplicates'] = true;
711  }
712 
713  $allSpecifier = $settings[self::PARAM_ALL] ?? false;
714  if ( $allSpecifier !== false ) {
715  if ( !is_string( $allSpecifier ) ) {
716  $allSpecifier = self::ALL_DEFAULT_STRING;
717  }
718  $info['allspecifier'] = $allSpecifier;
719  }
720  }
721 
722  if ( $typeDef ) {
723  $info = array_merge( $info, $typeDef->getParamInfo( $name, $settings, $options ) );
724  }
725 
726  // Filter out nulls (strictly)
727  return array_filter( $info, function ( $v ) {
728  return $v !== null;
729  } );
730  }
731 
741  public function getHelpInfo( $name, $settings, array $options ) {
742  $settings = $this->normalizeSettings( $settings );
743  $typeDef = $this->getTypeDef( $settings[self::PARAM_TYPE] );
744 
745  // Define ordering. Some are overwritten below, some expected from the TypeDef
746  $info = [
747  self::PARAM_DEPRECATED => null,
748  self::PARAM_REQUIRED => null,
749  self::PARAM_SENSITIVE => null,
750  self::PARAM_TYPE => null,
751  self::PARAM_ISMULTI => null,
752  self::PARAM_ISMULTI_LIMIT1 => null,
753  self::PARAM_ALL => null,
754  self::PARAM_DEFAULT => null,
755  ];
756 
757  if ( !empty( $settings[self::PARAM_DEPRECATED] ) ) {
758  $info[self::PARAM_DEPRECATED] = MessageValue::new( 'paramvalidator-help-deprecated' );
759  }
760 
761  if ( !empty( $settings[self::PARAM_REQUIRED] ) ) {
762  $info[self::PARAM_REQUIRED] = MessageValue::new( 'paramvalidator-help-required' );
763  }
764 
765  if ( !empty( $settings[self::PARAM_ISMULTI] ) ) {
766  $info[self::PARAM_ISMULTI] = MessageValue::new( 'paramvalidator-help-multi-separate' );
767 
768  $lowcount = $settings[self::PARAM_ISMULTI_LIMIT1] ?? $this->ismultiLimit1;
769  $highcount = max( $lowcount, $settings[self::PARAM_ISMULTI_LIMIT2] ?? $this->ismultiLimit2 );
770  $values = $typeDef ? $typeDef->getEnumValues( $name, $settings, $options ) : null;
771  if (
772  // Only mention the limits if they're likely to matter.
773  $values === null || count( $values ) > $lowcount ||
774  !empty( $settings[self::PARAM_ALLOW_DUPLICATES] )
775  ) {
776  if ( $highcount > $lowcount ) {
777  $info[self::PARAM_ISMULTI_LIMIT1] = MessageValue::new( 'paramvalidator-help-multi-max' )
778  ->numParams( $lowcount, $highcount );
779  } else {
780  $info[self::PARAM_ISMULTI_LIMIT1] = MessageValue::new( 'paramvalidator-help-multi-max-simple' )
781  ->numParams( $lowcount );
782  }
783  }
784 
785  $allSpecifier = $settings[self::PARAM_ALL] ?? false;
786  if ( $allSpecifier !== false ) {
787  if ( !is_string( $allSpecifier ) ) {
788  $allSpecifier = self::ALL_DEFAULT_STRING;
789  }
790  $info[self::PARAM_ALL] = MessageValue::new( 'paramvalidator-help-multi-all' )
791  ->plaintextParams( $allSpecifier );
792  }
793  }
794 
795  if ( isset( $settings[self::PARAM_DEFAULT] ) && $typeDef ) {
796  $value = $typeDef->stringifyValue( $name, $settings[self::PARAM_DEFAULT], $settings, $options );
797  if ( $value === '' ) {
798  $info[self::PARAM_DEFAULT] = MessageValue::new( 'paramvalidator-help-default-empty' );
799  } elseif ( $value !== null ) {
800  $info[self::PARAM_DEFAULT] = MessageValue::new( 'paramvalidator-help-default' )
801  ->plaintextParams( $value );
802  }
803  }
804 
805  if ( $typeDef ) {
806  $info = array_merge( $info, $typeDef->getHelpInfo( $name, $settings, $options ) );
807  }
808 
809  // Put the default at the very end (the TypeDef may have added extra messages)
810  $default = $info[self::PARAM_DEFAULT];
811  unset( $info[self::PARAM_DEFAULT] );
812  $info[self::PARAM_DEFAULT] = $default;
813 
814  // Filter out nulls
815  return array_filter( $info );
816  }
817 
828  public static function explodeMultiValue( $value, $limit ) {
829  if ( $value === '' || $value === "\x1f" ) {
830  return [];
831  }
832 
833  if ( substr( $value, 0, 1 ) === "\x1f" ) {
834  $sep = "\x1f";
835  $value = substr( $value, 1 );
836  } else {
837  $sep = '|';
838  }
839 
840  return explode( $sep, $value, $limit );
841  }
842 
849  public static function implodeMultiValue( array $value ) {
850  if ( $value === [ '' ] ) {
851  // There's no value that actually returns a single empty string.
852  // Best we can do is this that returns two, which will be deduplicated to one.
853  return '|';
854  }
855 
856  foreach ( $value as $v ) {
857  if ( strpos( $v, '|' ) !== false ) {
858  return "\x1f" . implode( "\x1f", $value );
859  }
860  }
861  return implode( '|', $value );
862  }
863 
864 }
Wikimedia\ParamValidator\ParamValidator\implodeMultiValue
static implodeMultiValue(array $value)
Implode an array as a multi-valued parameter string, like implode()
Definition: ParamValidator.php:849
Wikimedia\ParamValidator
Definition: Callbacks.php:3
Wikimedia\ParamValidator\ParamValidator\$typeDefs
TypeDef array[] $typeDefs
Map parameter type names to TypeDef objects or ObjectFactory specs.
Definition: ParamValidator.php:204
Wikimedia\Message\ParamType\PLAINTEXT
const PLAINTEXT
A text parameter which is substituted after formatter processing.
Definition: ParamType.php:64
Wikimedia\ParamValidator\ParamValidator\$STANDARD_TYPES
static $STANDARD_TYPES
A list of standard type names and types that may be passed as $typeDefs to __construct().
Definition: ParamValidator.php:176
Wikimedia\ParamValidator\ValidationException
Error reporting for ParamValidator.
Definition: ValidationException.php:16
Wikimedia\ParamValidator\Callbacks
Interface defining callbacks needed by ParamValidator.
Definition: Callbacks.php:21
Wikimedia\ParamValidator\ParamValidator\getValue
getValue( $name, $settings, array $options=[])
Fetch and validate a parameter value using a settings array.
Definition: ParamValidator.php:514
Wikimedia\ParamValidator\ParamValidator\PARAM_ISMULTI_LIMIT1
const PARAM_ISMULTI_LIMIT1
(int) Maximum number of multi-valued parameter values allowed
Definition: ParamValidator.php:119
Wikimedia\ParamValidator\ParamValidator\explodeMultiValue
static explodeMultiValue( $value, $limit)
Split a multi-valued parameter string, like explode()
Definition: ParamValidator.php:828
Wikimedia\ParamValidator\ParamValidator\$ismultiLimit2
int $ismultiLimit2
Default values for PARAM_ISMULTI_LIMIT2.
Definition: ParamValidator.php:210
Wikimedia\ParamValidator\ParamValidator\getTypeDef
getTypeDef( $type)
Get the TypeDef for a type.
Definition: ParamValidator.php:314
Wikimedia\ParamValidator\ParamValidator\normalizeSettings
normalizeSettings( $settings)
Normalize a parameter settings array.
Definition: ParamValidator.php:362
Wikimedia\ParamValidator\ParamValidator\PARAM_ALLOW_DUPLICATES
const PARAM_ALLOW_DUPLICATES
(bool) Allow the same value to be set more than once when PARAM_ISMULTI is true?
Definition: ParamValidator.php:145
Wikimedia\ParamValidator\ParamValidator\PARAM_IGNORE_UNRECOGNIZED_VALUES
const PARAM_IGNORE_UNRECOGNIZED_VALUES
(bool) Whether to downgrade "badvalue" errors to non-fatal when validating multi-valued parameters.
Definition: ParamValidator.php:168
Wikimedia\ParamValidator\ParamValidator\$objectFactory
ObjectFactory $objectFactory
Definition: ParamValidator.php:201
Wikimedia\Message\ScalarParam
Value object representing a message parameter holding a single value.
Definition: ScalarParam.php:12
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:16
Wikimedia\ParamValidator\ParamValidator\ALL_DEFAULT_STRING
const ALL_DEFAULT_STRING
Magic "all values" value when PARAM_ALL is true.
Definition: ParamValidator.php:173
Wikimedia\ParamValidator\ParamValidator\$ismultiLimit1
int $ismultiLimit1
Default values for PARAM_ISMULTI_LIMIT1.
Definition: ParamValidator.php:207
Wikimedia\ParamValidator\ParamValidator\PARAM_SENSITIVE
const PARAM_SENSITIVE
(bool) Indicate that the parameter's value should not be logged.
Definition: ParamValidator.php:153
Wikimedia\ParamValidator\TypeDef
Base definition for ParamValidator types.
Definition: TypeDef.php:19
Wikimedia\ParamValidator\ValidationException\getFailureMessage
getFailureMessage()
Fetch the validation failure message.
Definition: ValidationException.php:63
Wikimedia\ParamValidator\ParamValidator\PARAM_REQUIRED
const PARAM_REQUIRED
(bool) Indicate that the parameter is required.
Definition: ParamValidator.php:84
Wikimedia\ParamValidator\ParamValidator\PARAM_ALL
const PARAM_ALL
(bool|string) Whether a magic "all values" value exists for multi-valued enumerated types,...
Definition: ParamValidator.php:137
Wikimedia\ParamValidator\ParamValidator\overrideTypeDef
overrideTypeDef( $name, $typeDef)
Register a type handler, overriding any existing handler.
Definition: ParamValidator.php:286
Wikimedia\ParamValidator\ParamValidator\addTypeDefs
addTypeDefs(array $typeDefs)
Register multiple type handlers.
Definition: ParamValidator.php:248
Wikimedia\ParamValidator\ParamValidator\knownTypes
knownTypes()
List known type names.
Definition: ParamValidator.php:238
Wikimedia\ParamValidator\ParamValidator\$callbacks
Callbacks $callbacks
Definition: ParamValidator.php:198
Wikimedia\ParamValidator\ParamValidator\PARAM_ISMULTI
const PARAM_ISMULTI
(bool) Indicate that the parameter is multi-valued.
Definition: ParamValidator.php:112
Wikimedia\Message\DataMessageValue
Value object representing a message for i18n with alternative machine-readable data.
Definition: DataMessageValue.php:23
Wikimedia\ParamValidator\ParamValidator\hasTypeDef
hasTypeDef( $name)
Test if a type is registered.
Definition: ParamValidator.php:305
Wikimedia\ParamValidator\ParamValidator\__construct
__construct(Callbacks $callbacks, ObjectFactory $objectFactory, array $options=[])
Definition: ParamValidator.php:221
Wikimedia\Message\DataMessageValue\new
static new( $key, $params=[], $code=null, array $data=null)
Static constructor for easier chaining of ->params() methods.
Definition: DataMessageValue.php:55
Wikimedia\ParamValidator\ParamValidator\getParamInfo
getParamInfo( $name, $settings, array $options)
Describe parameter settings in a machine-readable format.
Definition: ParamValidator.php:682
Wikimedia\ParamValidator\ParamValidator\PARAM_ISMULTI_LIMIT2
const PARAM_ISMULTI_LIMIT2
(int) Maximum number of multi-valued parameter values allowed for users allowed high limits.
Definition: ParamValidator.php:127
Wikimedia\ParamValidator\ParamValidator\normalizeSettingsInternal
normalizeSettingsInternal( $settings)
Logic shared by normalizeSettings() and checkSettings()
Definition: ParamValidator.php:340
Wikimedia\Message\MessageValue\new
static new( $key, $params=[])
Static constructor for easier chaining of ->params() methods.
Definition: MessageValue.php:42
Wikimedia\ParamValidator\ParamValidator\addTypeDef
addTypeDef( $name, $typeDef)
Register a type handler.
Definition: ParamValidator.php:267
Wikimedia\ParamValidator\ParamValidator\validateValue
validateValue( $name, $value, $settings, array $options=[])
Validate a parameter value using a settings array.
Definition: ParamValidator.php:566
Wikimedia\ParamValidator\ParamValidator\PARAM_DEFAULT
const PARAM_DEFAULT
(mixed) Default value of the parameter.
Definition: ParamValidator.php:68
Wikimedia\ParamValidator\ParamValidator\PARAM_TYPE
const PARAM_TYPE
(string|array) Type of the parameter.
Definition: ParamValidator.php:76
Wikimedia\ParamValidator\ParamValidator\PARAM_DEPRECATED
const PARAM_DEPRECATED
(bool) Indicate that a deprecated parameter was used.
Definition: ParamValidator.php:161
Wikimedia\ParamValidator\ParamValidator\checkSettings
checkSettings(string $name, $settings, array $options)
Validate a parameter settings array.
Definition: ParamValidator.php:391
Wikimedia\ParamValidator\ParamValidator
Service for formatting and validating API parameters.
Definition: ParamValidator.php:42
Wikimedia\ParamValidator\ParamValidator\getHelpInfo
getHelpInfo( $name, $settings, array $options)
Describe parameter settings in human-readable format.
Definition: ParamValidator.php:741
Wikimedia\Message\ParamType
The constants used to specify parameter types.
Definition: ParamType.php:11
$type
$type
Definition: testCompression.php:52