Re: DataObject validation
| From: | Alan Knowles | Date: | Wed, 05 Mar 2003 11:07:25 +0000 |
| Subject: | Re: DataObject validation | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4038@lists.php.net to get a copy of this message | ||
The point of validation is really to provide a minimal type checking hook. - if you need to validate the existance of keys it's probably worth adding to your class
function validate () {
$must = array('name','age',...);
$ret = array();
foreach($must as $check) {
if (strlen($this->$check)) {
$ret[$check] = "$check is not set";
}
}
$typecheck = parent::validate();
if (!is_array($typecheck) && empty($ret)) {
return true;
}
return array_merge($typecheck,$ret);
}
... etc.
the LDAP version of DataObjects does do these checks as columns are defined as 'must' in LDAP.. - but at the moment the table information does not hold information about columns that are 'not null' and do not have defaults..
There is a long term plan to look more at expanding the table details - probably using cached serialized xml data (maybe from mdb).. - but I've not really had a great need for this yet..
Regards
Alan
Conrad Dare-Edwards wrote:
The DB_DataObject validate function skips keys that are not set without error. Is this a feature I would have through that the point of the validation was to allow the child class to determine that this is a problem or not. Tell me if there is a better forum for this. Cheers Conrad.