<?php
abstract class Validate {
public static $_Exceptions;
public static function Run($o) {
if($o->_HtmlOut == true) {
$o->HtmlOutput(false);
$Was_Html = true;
}
try {
if(!is_array($o->_Fields))
throw new Exception("Os campos ainda não foram definidos.");
foreach($o->_Fields as $Field) {
if(is_empty($o->{$Field}) && in_array($Field, $o->_NotNull));
throw new Exception("O campo ". $Field ." da tabela ". $o->_Table ." não pode ser vazio.");
switch(strtolower($o->_Meta[$Field]))
{
case('date') :
if(!self::Date($o->{$Field}, Format::DATE))
self::$Errors[] = $Field;
break;
case('datetime') :
if(!self::Date($o->{$Field}, Format::DATETIME))
self::$Errors[] = $Field;
break;
case('string') :
if(!is_string($o->{$Field}))
self::$Errors[] = $Field;
break;
case('int') :
if(!is_int($o->{$Field}))
if((int)($o->{$Field}) == $o->{$Field})
self::$Errors[] = $Field;
break;
}
}
}
catch(Exception $e) {
throw $e;
}
finally {
if($Was_Html == true)
$o->HtmlOutput(false);
}
if(is_array($Errors))
foreach($Errors as $Field)
self::$_Exceptions[] = "Valor '". $o->{$Field} ."' para o campo ". $Field ."(".$o->_Meta[$Field].") da tabela ". $o->_Table ." é inválido";
self::_Throw();
return true;
}
public static function Date($data, Validate $type) {
switch($type) {
case(self::DATE) :
if (date(DATE, strtotime($data)) == $data)
return true;
break;
case(self::DATE_TIME) :
if (date(DATE, strtotime($data)) == $data)
return true;
break;
}
return false;
}
public static function _Throw() {
if (!is_array(self::$_Exceptions))
return false;
$Exception = implode('<br />', self::$_Exceptions);
unset(self::$_Exceptions);
throw new Exception($Exception);
}
}
?>
- Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
- Parse error: syntax error, unexpected '{' in /in/3tFjU on line 56
Process exited with code 255. - Output for 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '{' in /in/3tFjU on line 56
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected T_CLASS in /in/3tFjU on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
- Parse error: parse error, unexpected T_CLASS in /in/3tFjU on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/3tFjU on line 3
Process exited with code 255.
preferences:
289.88 ms | 401 KiB | 351 Q