cyrilleinvalides/choupas/www/admin/app/libs/sense/Entity/Elements/ElementString.php

50 lines
1.1 KiB
PHP
Executable File

<?php
class ElementString extends Element {
private static $schema;
public static function getDefinition () {
if ( self::$schema )
return static::$schema;
return static::$schema= self::getSchema(array(
'minlength' => ElementInteger::getSchema(array('default' => false, 'null' => true)),
'maxlength' => ElementInteger::getSchema(array('default' => false, 'null' => true)),
'default' => ElementBoolean::getSchema(array('default' => false, 'null' => true)),
'null' => ElementBoolean::getSchema(array('default' => true, 'null' => true))
));
}
public static function getSchema ( $params = array() ) {
$params['type'] = 'string';
return $params;
}
public static function invalid ( $schema, $value, $data = array() ) {
if ( $error = parent::invalid($schema, $value, $data) )
return $error;
if ( is_null($value) || is_string($value) )
return false;
return 'Value is not a string !';
}
public static function apply ( $schema, $value, $data = array() ) {
return (string) parent::apply($schema, $value, $data);
}
}
?>