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