Commit 8fbd1820 authored by meus's avatar meus

conveience method inspect() in Doctrine_Validator_Exception. Call it with...

conveience method inspect() in Doctrine_Validator_Exception. Call it with user_func and it will apply it to all ErrorStacks
parent 3ad6e01c
...@@ -184,7 +184,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -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 = $this->_table->getRepository();
$repository->add($this); $repository->add($this);
......
...@@ -39,13 +39,16 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable ...@@ -39,13 +39,16 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
* @var array * @var array
*/ */
protected $errors = array(); protected $errors = array();
protected $classname = "";
/** /**
* Constructor * Constructor
* *
*/ */
public function __construct() public function __construct($classname = "")
{} {
$this->classname = $classname;
}
/** /**
* Adds an error to the stack. * Adds an error to the stack.
...@@ -127,4 +130,12 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable ...@@ -127,4 +130,12 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
{ {
return count($this->errors); return count($this->errors);
} }
/**
* Get the classname where the errors occured
*
*/
public function getClassname(){
return $this->classname;
}
} }
...@@ -70,6 +70,9 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab ...@@ -70,6 +70,9 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab
return parent::__toString(); return parent::__toString();
} }
/**
* Generate a message with all classes that have exceptions
*/
private function generateMessage() private function generateMessage()
{ {
$message = ""; $message = "";
...@@ -79,4 +82,17 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab ...@@ -79,4 +82,17 @@ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countab
return $message; 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());
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment