MediaWiki
master
Toggle main menu visibility
PresenceBooleanDef.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Wikimedia\ParamValidator\TypeDef;
4
5
use Wikimedia\Message\MessageValue;
6
use Wikimedia\ParamValidator\ParamValidator;
7
use Wikimedia\ParamValidator\TypeDef;
8
21
class
PresenceBooleanDef
extends
TypeDef
{
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"
84
$info[
ParamValidator::PARAM_DEFAULT
] =
null
;
85
86
return
$info;
87
}
88
89
}
Wikimedia\ParamValidator\ParamValidator\PARAM_ISMULTI
const PARAM_ISMULTI
(bool) Indicate that the parameter is multi-valued.
Definition
ParamValidator.php:112
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\TypeDef\PresenceBooleanDef
Type definition for checkbox-like boolean types.
Definition
PresenceBooleanDef.php:21
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\getParamInfo
getParamInfo( $name, array $settings, array $options)
Describe parameter settings in a machine-readable format.Keys should be short strings using lowercase...
Definition
PresenceBooleanDef.php:66
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\normalizeSettings
normalizeSettings(array $settings)
Normalize a settings array.to override array
Definition
PresenceBooleanDef.php:34
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\getValue
getValue( $name, array $settings, array $options)
Get the value from the request.to overrideOnly override this if you need to use something other than ...
Definition
PresenceBooleanDef.php:24
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\getHelpInfo
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.Keys in the returned array should generally corr...
Definition
PresenceBooleanDef.php:76
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\validate
validate( $name, $value, array $settings, array $options)
Validate the value.When ParamValidator is processing a multi-valued parameter, this will be called on...
Definition
PresenceBooleanDef.php:29
Wikimedia\ParamValidator\TypeDef\PresenceBooleanDef\checkSettings
checkSettings(string $name, $settings, array $options, array $ret)
Validate a parameter settings array.This is intended for validation of parameter settings during unit...
Definition
PresenceBooleanDef.php:45
Wikimedia\ParamValidator\TypeDef
Definition
BinaryBooleanDef.php:3
includes
libs
ParamValidator
TypeDef
PresenceBooleanDef.php
Generated on
for MediaWiki by
1.18.0