cvs: pear /DB_DataObject DataObject.php
| From: | Alan Knowles | Date: | Thu, 15 Aug 2002 04:48:23 +0000 |
| Subject: | cvs: pear /DB_DataObject DataObject.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5749@lists.php.net to get a copy of this message | ||
alan_k Thu Aug 15 00:48:23 2002 EDT
Modified files:
/pear/DB_DataObject DataObject.php
Log:
not a good idea working on old versions - thank god for CVS
Index: pear/DB_DataObject/DataObject.php
diff -u pear/DB_DataObject/DataObject.php:1.18 pear/DB_DataObject/DataObject.php:1.19
--- pear/DB_DataObject/DataObject.php:1.18 Thu Aug 15 00:12:19 2002
+++ pear/DB_DataObject/DataObject.php Thu Aug 15 00:48:23 2002
@@ -15,7 +15,7 @@
// | Author: Alan Knowles <alan@akbkhome.com>
// +----------------------------------------------------------------------+
//
-// $Id: DataObject.php,v 1.18 2002/08/15 04:12:19 alan_k Exp $
+// $Id: DataObject.php,v 1.19 2002/08/15 04:48:23 alan_k Exp $
//
// Object Based Database Query Builder and data store
//
@@ -1247,7 +1247,7 @@
continue; // ignore empty keys!!! what
}
if (is_object($from) && @isset($from->$k)) {
- $this->$k = $this->$k;
+ $this->$k = $from->$k;
continue;
}
if (!@isset($from[$k])) {
@@ -1262,8 +1262,49 @@
$this->$k = $from[$k];
}
return TRUE;
- }
-
+ }
+
+ /**
+ * validate - override this to set up your validation rules
+ *
+ * validate the current objects values either just testing strings/numbers or
+ * using the user defined validate{Row name}() methods.
+ * will attempt to call $this->validate{column_name}() - expects TRUE = ok FALSE = ERROR
+ * you can the use the validate Class from your own methods.
+ *
+ * @access public
+ * @return array of validation results or TRUE
+ */
+ function validate()
+ {
+ require_once("Validate.php");
+ $table = &$this->_get_table();
+ $ret = array();
+
+ foreach($table as $key=>$val) {
+ if (!isset($this->$key)) continue;
+ $method = "Validate".ucfirst($key);
+ if (method_exists($this,$method)) {
+ $ret[$key] = $this->$method();
+ continue;
+ }
+ switch ($val) {
+ case DB_DATAOBJECT_STR:
+ $ret[$key] = Validate::string($this->$key, VAL_PUNCTUATION . VAL_NAME);
+ continue;
+ case DB_DATAOBJECT_INT:
+ $ret[$key] = Validate::number($this->$key, ".");
+ continue;
+ }
+ }
+
+ foreach ($ret as $key=>$val) {
+ if ($val == FALSE) return $ret;
+ }
+ return TRUE; // everything is OK.
+ }
+
+
/* ----------------------- Debugger ------------------ */
/**
* Debugger. - use this in your extended classes to output debugging information.