47 lines
927 B
PHP
Executable File
47 lines
927 B
PHP
Executable File
<?php
|
|
|
|
class ElementBoolean extends Element {
|
|
|
|
private static $schema;
|
|
|
|
public static function getDefinition () {
|
|
|
|
if ( self::$schema )
|
|
return static::$schema;
|
|
|
|
return static::$schema= self::getSchema(array(
|
|
'default' => self::getSchema(array('default' => null, 'null' => true)),
|
|
'null' => self::getSchema(array('default' => null, 'null' => true))
|
|
));
|
|
|
|
}
|
|
|
|
public static function getSchema ( $params = array() ) {
|
|
|
|
$params['type'] = 'boolean';
|
|
return $params;
|
|
|
|
}
|
|
|
|
public static function invalid ( $schema, $value, $data = array() ) {
|
|
|
|
if ( $error = parent::invalid($schema, $value, $data) )
|
|
return $error;
|
|
|
|
if ( is_null($value) || is_bool($value) )
|
|
return false;
|
|
|
|
return 'Value is not a boolean !';
|
|
|
|
}
|
|
|
|
public static function apply ( $schema, $value, $data = array() ) {
|
|
|
|
return (bool) $value;
|
|
return (bool) parent::apply($schema, $value, $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|