Merge "Type hint against LinkTarget in WatchedItemStore"
[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 */
18 class PresenceBooleanDef extends TypeDef {
19
20 public function getValue( $name, array $settings, array $options ) {
21 return $this->callbacks->hasParam( $name, $options );
22 }
23
24 public function validate( $name, $value, array $settings, array $options ) {
25 return (bool)$value;
26 }
27
28 public function describeSettings( $name, array $settings, array $options ) {
29 $info = parent::describeSettings( $name, $settings, $options );
30 unset( $info['default'] );
31 return $info;
32 }
33
34 }