60 lines
1.3 KiB
PHP
Executable File
60 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
define('INT_32_MAX', pow(2, 32));
|
|
define('INT_32_MIN', -INT_32_MAX - 1);
|
|
|
|
class ElementInteger extends Element {
|
|
|
|
const
|
|
_MIN = INT_32_MIN,
|
|
_MAX = INT_32_MAX;
|
|
|
|
private static $schema;
|
|
|
|
public static function getDefinition () {
|
|
|
|
if ( self::$schema )
|
|
return static::$schema;
|
|
|
|
return static::$schema= self::getSchema(array(
|
|
'min' => self::getSchema(array('min' => self::_MIN, 'max' => self::_MAX, 'default' => self::_MIN, 'null' => true)),
|
|
'max' => self::getSchema(array('min' => self::_MIN, 'max' => self::_MAX, 'default' => self::_MAX, 'null' => true)),
|
|
'default' => ElementBoolean::getSchema(array('default' => null, 'null' => true)),
|
|
'null' => ElementBoolean::getSchema(array('default' => true, 'null' => true))
|
|
));
|
|
|
|
}
|
|
|
|
public static function getSchema ( $params = array() ) {
|
|
|
|
$params['type'] = 'integer';
|
|
return $params;
|
|
|
|
}
|
|
|
|
public static function invalid ( $schema, $value, $data = array() ) {
|
|
|
|
if ( $error = parent::invalid($schema, $value, $data) )
|
|
return $error;
|
|
|
|
if ( is_null($value) || is_int($value) )
|
|
return false;
|
|
|
|
return 'Value is not an integer !';
|
|
|
|
}
|
|
|
|
public static function apply ( $schema, $value, $data = array() ) {
|
|
|
|
if ( !$value )
|
|
$value = 0;
|
|
|
|
else $value = (int) $value;
|
|
|
|
return (int) parent::apply($schema, $value, $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|