. */ Doctrine::autoload('Doctrine_Exception'); /** * Doctrine_Validator_Exception * * @package Doctrine * @subpackage Validator * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ */ class Doctrine_Validator_Exception extends Doctrine_Exception implements Countable, IteratorAggregate { /** * @var array $invalid */ private $invalid = array(); /** * @param Doctrine_Validator $validator */ public function __construct(array $invalid) { $this->invalid = $invalid; parent::__construct($this->generateMessage()); } public function getInvalidRecords() { return $this->invalid; } public function getIterator() { return new ArrayIterator($this->invalid); } public function count() { return count($this->invalid); } /** * __toString * * @return string */ public function __toString() { return parent::__toString(); } /** * Generate a message with all classes that have exceptions */ private function generateMessage() { $message = ""; foreach ($this->invalid as $record) { $message .= "Validaton error in class " . get_class($record) . " "; } 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()); } } }