1
0
mirror of synced 2024-12-13 22:56:04 +03:00

conveience method inspect() in Doctrine_Validator_Exception. Call it with user_func and it will apply it to all ErrorStacks

This commit is contained in:
meus 2007-09-08 12:41:09 +00:00
parent 3ad6e01c73
commit 8fbd18207b
3 changed files with 30 additions and 3 deletions

View File

@ -184,7 +184,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
}
$this->_errorStack = new Doctrine_Validator_ErrorStack();
$this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this));
$repository = $this->_table->getRepository();
$repository->add($this);

View File

@ -39,13 +39,16 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
* @var array
*/
protected $errors = array();
protected $classname = "";
/**
* Constructor
*
*/
public function __construct()
{}
public function __construct($classname = "")
{
$this->classname = $classname;
}
/**
* Adds an error to the stack.
@ -127,4 +130,12 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
{
return count($this->errors);
}
/**
* Get the classname where the errors occured
*
*/
public function getClassname(){
return $this->classname;
}
}

View File

@ -70,6 +70,9 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab
return parent::__toString();
}
/**
* Generate a message with all classes that have exceptions
*/
private function generateMessage()
{
$message = "";
@ -79,4 +82,17 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab
return $message;
}
/**
* This method will apply the value of the $function variable as a user_func
* to tall errorstack objects in the exception
*
* @param mixed Either string with function name or array with object,
* functionname. See call_user_func in php manual for more inforamtion
*/
public function inspect($function){
foreach($this->invalid as $record){
call_user_func($function, $record->getErrorStack());
}
}
}