<?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";
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() {
$Exception = implode('<br />', self::$_Exceptions);
unset(self::$_Exceptions);
throw new Exception($Exception);
}
}
?>
- Output for 5.4.0 - 5.4.24
- Parse error: syntax error, unexpected '}', expecting catch (T_CATCH) in /in/0tH7f on line 54
Process exited with code 255. - Output for 5.3.0 - 5.3.28
- Parse error: syntax error, unexpected '}', expecting T_CATCH in /in/0tH7f on line 54
Process exited with code 255.
preferences:
184.54 ms | 1395 KiB | 61 Q