dblayer : return all the verify errors in the same shot

dblayer : allow to have external verifyOne and verifyAll functions


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2911 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-07-19 13:28:37 +00:00
parent bc0bd0d1e7
commit 9a697c0034

View File

@@ -60,8 +60,10 @@ class dblayer
/** Titles */
public $titles = array ();
public $verifyOne = array ("dblayer", "verifyOne");
public $verifyAll = array ("dblayer", "verifyAll");
/** Define the name of the method to use to verify each entry */
public $verifyOneFunc;
/** Define the name of the method to use to verify all entries */
public $verifyAllFunc;
/** The verify unitary stack
@param string $field The name of the field to test
@@ -100,6 +102,9 @@ class dblayer
public function __construct ($dsn, $username=null, $password=null,
$driver_options=null)
{
$this->verifyOneFunc = array ($this, "verifyOne");
$this->verifyAllFunc = array ($this, "verifyAll");
$driver = @explode (":", $dsn);
if (! isset ($driver[0]))
throw new Exception (dgettext("domframework", "No valid DSN provided"),
@@ -298,7 +303,7 @@ class dblayer
continue;
// Verify the fields, if $verify is defined, before doing insertion
$verify = call_user_func ($this->verifyOne, $key, $data[$key]);
$verify = call_user_func ($this->verifyOneFunc, $key, $data[$key]);
if (is_array ($verify) && count ($verify))
{
$errors[$key] = array ($verify[0], $verify[1]);
@@ -388,14 +393,14 @@ class dblayer
}
}
if (count ($errors) !== 0)
return $errors;
if ($this->debug) echo " verify inconsistency\n";
// Check for inconsistency
$verify = call_user_func ($this->verifyAll, $data);
if (count ($verify))
return $verify;
$verify = call_user_func ($this->verifyAllFunc, $data);
if (is_null ($verify))
$verify = array ();
$allErrors = array_merge ($errors, $verify);
if (count ($allErrors))
return $allErrors;
$dataOK = array ();
foreach ($this->fields as $field=>$desc)