MediaWiki master
PresenceBooleanDef.php
Go to the documentation of this file.
1<?php
2
4
8
22
24 public function getValue( $name, array $settings, array $options ) {
25 return $this->callbacks->hasParam( $name, $options ) ? true : null;
26 }
27
29 public function validate( $name, $value, array $settings, array $options ) {
30 return (bool)$value;
31 }
32
34 public function normalizeSettings( array $settings ) {
35 // Cannot be multi-valued
36 $settings[ParamValidator::PARAM_ISMULTI] = false;
37
38 // Default the default to false so ParamValidator::getValue() returns false (T244440)
39 $settings += [ ParamValidator::PARAM_DEFAULT => false ];
40
41 return parent::normalizeSettings( $settings );
42 }
43
45 public function checkSettings( string $name, $settings, array $options, array $ret ): array {
46 $ret = parent::checkSettings( $name, $settings, $options, $ret );
47
48 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
49 !isset( $ret['issues'][ParamValidator::PARAM_ISMULTI] )
50 ) {
51 $ret['issues'][ParamValidator::PARAM_ISMULTI] =
52 'PARAM_ISMULTI cannot be used for presence-boolean-type parameters';
53 }
54
55 if ( ( $settings[ParamValidator::PARAM_DEFAULT] ?? false ) !== false &&
56 !isset( $ret['issues'][ParamValidator::PARAM_DEFAULT] )
57 ) {
58 $ret['issues'][ParamValidator::PARAM_DEFAULT] =
59 'Default for presence-boolean-type parameters must be false or null';
60 }
61
62 return $ret;
63 }
64
66 public function getParamInfo( $name, array $settings, array $options ) {
67 $info = parent::getParamInfo( $name, $settings, $options );
68
69 // No need to report the default of "false"
70 $info['default'] = null;
71
72 return $info;
73 }
74
76 public function getHelpInfo( $name, array $settings, array $options ) {
77 $info = parent::getHelpInfo( $name, $settings, $options );
78
79 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
80 'paramvalidator-help-type-presenceboolean'
81 )->params( 1 );
82
83 // No need to report the default of "false"
85
86 return $info;
87 }
88
89}
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_DEFAULT
(mixed) Default value of the parameter.
const PARAM_TYPE
(string|array) Type of the parameter.
Type definition for checkbox-like boolean types.
getParamInfo( $name, array $settings, array $options)
Describe parameter settings in a machine-readable format.Keys should be short strings using lowercase...
normalizeSettings(array $settings)
Normalize a settings array.to override array
getValue( $name, array $settings, array $options)
Get the value from the request.to overrideOnly override this if you need to use something other than ...
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.Keys in the returned array should generally corr...
validate( $name, $value, array $settings, array $options)
Validate the value.When ParamValidator is processing a multi-valued parameter, this will be called on...
checkSettings(string $name, $settings, array $options, array $ret)
Validate a parameter settings array.This is intended for validation of parameter settings during unit...
Base definition for ParamValidator types.
Definition TypeDef.php:19