dblayeroo : Add normalize method by default

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4631 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-10-25 08:32:58 +00:00
parent 681863f187
commit 95f7b55681
2 changed files with 31 additions and 10 deletions

View File

@@ -1434,7 +1434,7 @@ class dblayeroo
*/
private static $sortOrder = 0;
/** The method to get a new sorti order acrossed the differents objects
/** The method to get a new sort order acrossed the differents objects
*/
public function getSortOrder ()
/* {{{ */
@@ -2343,6 +2343,7 @@ class dblayeroo
$this->debugLog ("Entering setValues (",$values,")");
if (! is_array ($values))
$this->DBException ("Invalid values to setValues : not an array");
$values = $this->normalize ($values);
$associative = null;
$tmpValues = array ();
$tmpType = array ();
@@ -2597,6 +2598,23 @@ class dblayeroo
}
/* }}} */
/** Normalize the values before using them.
* The normalize is called by methods : verify, checkRealTypes and setValues
* By default, remove the spaces (trim) at begin and end.
* This method can be overloaded by extending the class
* @param array $values The values to test or INSERT or UPDATE
* @return array the updated values
*/
public function normalize ($values)
// {{{
{
if (! is_array ($values))
$this->DBException ("Invalid values to normalize : not an array");
$values = array_map ("trim", $values);
return $values;
}
// }}}
/** Check the provided values which will be inserted or updated against the
* database structure.
* In update, do not forget to define the whereAdd parameters !
@@ -2614,6 +2632,7 @@ class dblayeroo
if ($this->primary === null)
throw new \Exception ("No primary key defined for table '$this->table'",
500);
$values = $this->normalize ($values);
if ($update === false)
{
// INSERT mode
@@ -2915,6 +2934,7 @@ class dblayeroo
if (! is_array ($values))
$this->DBException ("Invalid checkRealTypes provided : not an array",
500);
$values = $this->normalize ($values);
$errors = array ();
foreach ($this->fields as $field => $params)
{