MediaWiki REL1_34
TypeDef.php
Go to the documentation of this file.
1<?php
2
4
15abstract class TypeDef {
16
18 protected $callbacks;
19
20 public function __construct( Callbacks $callbacks ) {
21 $this->callbacks = $callbacks;
22 }
23
39 public function getValue( $name, array $settings, array $options ) {
40 return $this->callbacks->getValue( $name, null, $options );
41 }
42
61 abstract public function validate( $name, $value, array $settings, array $options );
62
68 public function normalizeSettings( array $settings ) {
69 return $settings;
70 }
71
85 public function getEnumValues( $name, array $settings, array $options ) {
86 return null;
87 }
88
104 public function stringifyValue( $name, $value, array $settings, array $options ) {
105 return (string)$value;
106 }
107
134 public function describeSettings( $name, array $settings, array $options ) {
135 $compact = !empty( $options['compact'] );
136
137 $ret = [];
138
139 if ( isset( $settings[ParamValidator::PARAM_DEFAULT] ) ) {
140 $value = $this->stringifyValue(
141 $name, $settings[ParamValidator::PARAM_DEFAULT], $settings, $options
142 );
143 $ret['default'] = $compact ? [ 'value' => $value ] : $value;
144 }
145
146 return $ret;
147 }
148
149}
const PARAM_DEFAULT
(mixed) Default value of the parameter.
Base definition for ParamValidator types.
Definition TypeDef.php:15
stringifyValue( $name, $value, array $settings, array $options)
Convert a value to a string representation.
Definition TypeDef.php:104
validate( $name, $value, array $settings, array $options)
Validate the value.
__construct(Callbacks $callbacks)
Definition TypeDef.php:20
describeSettings( $name, array $settings, array $options)
"Describe" a settings array
Definition TypeDef.php:134
getEnumValues( $name, array $settings, array $options)
Get the values for enum-like parameters.
Definition TypeDef.php:85
getValue( $name, array $settings, array $options)
Get the value from the request.
Definition TypeDef.php:39
normalizeSettings(array $settings)
Normalize a settings array.
Definition TypeDef.php:68
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:20