From 8fbd18207b0e9e45dab068e5a310c3b35334d703 Mon Sep 17 00:00:00 2001 From: meus <meus@625475ce-881a-0410-a577-b389adb331d8> Date: Sat, 8 Sep 2007 12:41:09 +0000 Subject: [PATCH] conveience method inspect() in Doctrine_Validator_Exception. Call it with user_func and it will apply it to all ErrorStacks --- lib/Doctrine/Record.php | 2 +- lib/Doctrine/Validator/ErrorStack.php | 15 +++++++++++++-- lib/Doctrine/Validator/Exception.php | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index aca821e21..20a4b84fd 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -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); diff --git a/lib/Doctrine/Validator/ErrorStack.php b/lib/Doctrine/Validator/ErrorStack.php index 9797fc7ca..7919fa77e 100644 --- a/lib/Doctrine/Validator/ErrorStack.php +++ b/lib/Doctrine/Validator/ErrorStack.php @@ -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; + } } diff --git a/lib/Doctrine/Validator/Exception.php b/lib/Doctrine/Validator/Exception.php index 9dc7ebd0c..c2d3060b2 100644 --- a/lib/Doctrine/Validator/Exception.php +++ b/lib/Doctrine/Validator/Exception.php @@ -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()); + } + } + } -- 2.21.0