MediaWiki REL1_35
IntegerDef.php
Go to the documentation of this file.
1<?php
2
4
7
23class IntegerDef extends NumericDef {
24
25 public function validate( $name, $value, array $settings, array $options ) {
26 if ( !preg_match( '/^[+-]?\d+$/D', $value ) ) {
27 $this->failure( 'badinteger', $name, $value, $settings, $options );
28 }
29 $ret = intval( $value, 10 );
30
31 // intval() returns min/max on overflow, so check that
32 if ( $ret === PHP_INT_MAX || $ret === PHP_INT_MIN ) {
33 $tmp = ( $ret < 0 ? '-' : '' ) . ltrim( $value, '-0' );
34 if ( $tmp !== (string)$ret ) {
35 $this->failure( 'badinteger', $name, $value, $settings, $options );
36 }
37 }
38
39 return $this->checkRange( $ret, $name, $value, $settings, $options );
40 }
41
42 public function getHelpInfo( $name, array $settings, array $options ) {
43 $info = parent::getHelpInfo( $name, $settings, $options );
44
45 $info[ParamValidator::PARAM_TYPE] = MessageValue::new( 'paramvalidator-help-type-integer' )
46 ->params( empty( $settings[ParamValidator::PARAM_ISMULTI] ) ? 1 : 2 );
47
48 return $info;
49 }
50
51}
Value object representing a message for i18n.
Service for formatting and validating API parameters.
const PARAM_ISMULTI
(bool) Indicate that the parameter is multi-valued.
const PARAM_TYPE
(string|array) Type of the parameter.
Type definition for integer types.
validate( $name, $value, array $settings, array $options)
Validate the value.
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.Keys in the returned array should generally corr...
Type definition base class for numeric types.
checkRange( $value, $name, $origValue, array $settings, array $options)
Check the range of a value.
failure( $failure, $name, $value, array $settings, array $options, $fatal=true)
Record a failure message.
Definition TypeDef.php:49