Author: jwage
Date: 2008-08-29 22:01:19 +0100 (Fri, 29 Aug 2008)
New Revision: 4865
Modified:
branches/1.0/lib/Doctrine/Event.php
branches/1.0/lib/Doctrine/Record.php
branches/1.0/lib/Doctrine/Record/Listener.php
branches/1.0/lib/Doctrine/Record/Listener/Chain.php
Log:
fixes #1081 - Added pre/postValidate() support
Modified: branches/1.0/lib/Doctrine/Event.php
===================================================================
--- branches/1.0/lib/Doctrine/Event.php 2008-08-29 20:45:05 UTC (rev 4864)
+++ branches/1.0/lib/Doctrine/Event.php 2008-08-29 21:01:19 UTC (rev 4865)
@@ -64,9 +64,10 @@
const RECORD_INSERT = 24;
const RECORD_SERIALIZE = 25;
const RECORD_UNSERIALIZE = 26;
+ const RECORD_DQL_DELETE = 27;
const RECORD_DQL_SELECT = 28;
- const RECORD_DQL_DELETE = 27;
const RECORD_DQL_UPDATE = 29;
+ const RECORD_VALIDATE = 30;
/**
* @var mixed $_invoker the handler which invoked this event
@@ -191,6 +192,8 @@
return 'delete records';
case self::RECORD_DQL_UPDATE:
return 'update records';
+ case self::RECORD_VALIDATE:
+ return 'validate record';
}
}
Modified: branches/1.0/lib/Doctrine/Record/Listener/Chain.php
===================================================================
--- branches/1.0/lib/Doctrine/Record/Listener/Chain.php 2008-08-29 20:45:05 UTC
(rev 4864)
+++ branches/1.0/lib/Doctrine/Record/Listener/Chain.php 2008-08-29 21:01:19 UTC
(rev 4865)
@@ -206,4 +206,18 @@
$listener->postHydrate($event);
}
}
-}
+
+ public function preValidate(Doctrine_Event $event)
+ {
+ foreach ($this->_listeners as $listener) {
+ $listener->preValidate($event);
+ }
+ }
+
+ public function postValidate(Doctrine_Event $event)
+ {
+ foreach ($this->_listeners as $listener) {
+ $listener->postValidate($event);
+ }
+ }
+}
\ No newline at end of file
Modified: branches/1.0/lib/Doctrine/Record/Listener.php
===================================================================
--- branches/1.0/lib/Doctrine/Record/Listener.php 2008-08-29 20:45:05 UTC
(rev 4864)
+++ branches/1.0/lib/Doctrine/Record/Listener.php 2008-08-29 21:01:19 UTC
(rev 4865)
@@ -82,4 +82,10 @@
public function postHydrate(Doctrine_Event $event)
{ }
+
+ public function preValidate(Doctrine_Event $event)
+ { }
+
+ public function postValidate(Doctrine_Event $event)
+ { }
}
\ No newline at end of file
Modified: branches/1.0/lib/Doctrine/Record.php
===================================================================
--- branches/1.0/lib/Doctrine/Record.php 2008-08-29 20:45:05 UTC (rev
4864)
+++ branches/1.0/lib/Doctrine/Record.php 2008-08-29 21:01:19 UTC (rev
4865)
@@ -285,15 +285,25 @@
$this->getErrorStack()->clear();
// Run validation process
- $validator = new Doctrine_Validator();
- $validator->validateRecord($this);
- $this->validate();
- if ($this->_state == self::STATE_TDIRTY || $this->_state ==
self::STATE_TCLEAN) {
- $this->validateOnInsert();
- } else {
- $this->validateOnUpdate();
+ $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE);
+ $this->preValidate($event);
+ $this->getTable()->getRecordListener()->preValidate($event);
+
+ if ( ! $event->skipOperation) {
+
+ $validator = new Doctrine_Validator();
+ $validator->validateRecord($this);
+ $this->validate();
+ if ($this->_state == self::STATE_TDIRTY || $this->_state ==
self::STATE_TCLEAN) {
+ $this->validateOnInsert();
+ } else {
+ $this->validateOnUpdate();
+ }
}
+ $this->getTable()->getRecordListener()->postValidate($event);
+ $this->postValidate($event);
+
return $this->getErrorStack()->count() == 0 ? true : false;
}
@@ -410,6 +420,20 @@
{ }
/**
+ * Empty template method to provide concrete Record classes with the
possibility
+ * to hook into the validation procedure. Useful for cleaning up data
before
+ * validating it.
+ */
+ public function preValidate($event)
+ { }
+ /**
+ * Empty template method to provide concrete Record classes with the
possibility
+ * to hook into the validation procedure.
+ */
+ public function postValidate($event)
+ { }
+
+ /**
* Empty template method to provide Record classes with the ability to
alter DQL select
* queries at runtime
*/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"doctrine-svn" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---