@ -26,122 +26,243 @@ class FormValidationException extends Exception {
}
}
class CPHPFormValidator
class ImmediateAbort extends FormValidationException { }
class CPHPFormValidatorPromiseBaseClass
{
public $previous = null;
public $next = null;
public function __construct($creator)
{
public function GenerateResultObject($failed, $critical)
$this->previous = $creator;
}
public function StartResolve()
{
if($failed === true && $critical === true)
/* Back and forth! */
if(is_null($this->previous) === true)
{
$object = new CPHPFormValidatorAbort();
$this->next->ContinueResolve(array());
}
else
{
$object = new CPHPFormValidatorResult();
$this->previous->StartResolve();
}
}
$object->handler = $this->handler;
return $object;
public function ContinueResolve($results)
{
$own_result = $this->Resolve($results);
if(is_null($own_result) === false)
{
$results[] = $own_result;
}
public function RequireKey($key, $critical = false)
if(is_null($this->next) === false)
{
$this->next->ContinueResolve($results);
}
else
{
return $this->ProcessSingleValidationResult($key, (!isset($this->handler->formdata[$key])), "required", "A value is required for this field.", $critical);
$this->ValidationFinished($results);
}
}
public function ValidateEmail($key, $critical = false)
throw new FormValidationException("A critical validation step failed.", $e->exceptions);
}
}
if($result !== true && $critical === true)
/* Operators */
public function Either($error_message)
{
return $return_object;
$this->next = new CPHPFormValidatorOperatorEither($this, $error_message, array_slice(func_get_args(), 1));
return $this->next;
}
public function All($error_message)
{
$this->next = new CPHPFormValidatorOperatorAll($this, $error_message, array_slice(func_get_args(), 1));
return $this->next;
}
return $return_object;
/* Validators */
public function RequireKey($key, $critical = false)
{
$this->next = new CPHPFormValidatorPromise($this, $this->handler, $key, array(), "required", "A value is required for this field.", $critical, function($key, $value, $args, $handler){
return isset($handler->formdata[$key]);
});
return $this->next;
}
else
public function ValidateEmail($key, $critical = false)
$this->next = new CPHPFormValidatorPromise($this, $this->handler, $key, array(), "email", "The value is not a valid e-mail address.", $critical, function($key, $value, $args, $handler){