ParamValidator: Flag as unstable for 1.34
[lhc/web/wiklou.git] / includes / libs / ParamValidator / TypeDef / PresenceBooleanDef.php
1 <?php
2
3 namespace Wikimedia\ParamValidator\TypeDef;
4
5 use Wikimedia\ParamValidator\TypeDef;
6
7 /**
8 * Type definition for checkbox-like boolean types
9 *
10 * This boolean is considered true if the parameter is present in the request,
11 * regardless of value. The only way for it to be false is for the parameter to
12 * be omitted entirely.
13 *
14 * The result from validate() is a PHP boolean.
15 *
16 * @since 1.34
17 * @unstable
18 */
19 class PresenceBooleanDef extends TypeDef {
20
21 public function getValue( $name, array $settings, array $options ) {
22 return $this->callbacks->hasParam( $name, $options );
23 }
24
25 public function validate( $name, $value, array $settings, array $options ) {
26 return (bool)$value;
27 }
28
29 public function describeSettings( $name, array $settings, array $options ) {
30 $info = parent::describeSettings( $name, $settings, $options );
31 unset( $info['default'] );
32 return $info;
33 }
34
35 }