Dblayer : set the @return with a type

This commit is contained in:
2022-07-22 10:10:23 +02:00
parent e9dea5b890
commit d68e0ac9c1

View File

@@ -112,13 +112,14 @@ class Dblayer
// Based on an idea of http://tonylandis.com/php/php5-pdo-singleton-class/ // Based on an idea of http://tonylandis.com/php/php5-pdo-singleton-class/
private static $instance = array (); private static $instance = array ();
/** Connection to the database engine /**
* See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format * Connection to the database engine
* @param string $dsn PDO Data Source Name * See http://fr2.php.net/manual/en/pdo.construct.php for the $dsn format
* @param string|null $username Username to connect * @param string $dsn PDO Data Source Name
* @param string|null $password Password to connect * @param string|null $username Username to connect
* @param string|null $driver_options Driver options to the database * @param string|null $password Password to connect
*/ * @param string|null $driver_options Driver options to the database
*/
public function __construct ($dsn, $username=null, $password=null, public function __construct ($dsn, $username=null, $password=null,
$driver_options=null) $driver_options=null)
{ {
@@ -232,8 +233,9 @@ class Dblayer
return self::$instance[$this->dsn]; return self::$instance[$this->dsn];
} }
/** Return the connected database name from DSN used to connect /**
*/ * Return the connected database name from DSN used to connect
*/
public function databasename () public function databasename ()
{ {
if ($this->sep === "") if ($this->sep === "")
@@ -251,8 +253,9 @@ class Dblayer
return NULL; return NULL;
} }
/** Return all the tables available in the database /**
*/ * Return all the tables available in the database
*/
public function listTables () public function listTables ()
{ {
if ($this->sep === "") if ($this->sep === "")
@@ -295,11 +298,12 @@ class Dblayer
return $res; return $res;
} }
/** Verify if the provided data can be inserted/updated in the database. /**
* @param array $data An array containing the data to verify with keys * Verify if the provided data can be inserted/updated in the database.
* @param mixed|null $updatekey the key to update * @param array $data An array containing the data to verify with keys
* @return an array with the errors in array($key=>array($priority,$message)) * @param mixed|null $updatekey the key to update
*/ * @return array an array with the errors in array($key=>array($priority,$message))
*/
public function verify ($data, $updatekey=false) public function verify ($data, $updatekey=false)
{ {
if ($this->debug) echo "== Entering verify\n"; if ($this->debug) echo "== Entering verify\n";
@@ -692,21 +696,22 @@ class Dblayer
return $lastID; return $lastID;
} }
/** Read the table content based on a select filter, ordered by order /**
* operator and the associated select value * Read the table content based on a select filter, ordered by order
* @param array|null $select Rows to select with * operator and the associated select value
* $select = array (array ($key, $val, $operator), ...) * @param array|null $select Rows to select with
* $key=>column, $val=>value to found, $operator=>'LIKE', =... * $select = array (array ($key, $val, $operator), ...)
* @param array|null $display Columns displayed * $key=>column, $val=>value to found, $operator=>'LIKE', =...
* $display = array ($col1, $col2...); * @param array|null $display Columns displayed
* @param array|null $order Sort the columns by orientation * $display = array ($col1, $col2...);
* $order = array (array ($key, $orientation), ...) * @param array|null $order Sort the columns by orientation
* $key=>column, $orientation=ASC/DESC * $order = array (array ($key, $orientation), ...)
* @param boolean|null $whereOr The WHERE parameters are separated by OR * $key=>column, $orientation=ASC/DESC
* instead of AND * @param boolean|null $whereOr The WHERE parameters are separated by OR
* @param array|null $foreignSelect Add a filter on foreign keys * instead of AND
* @return array array ([0] => array (column=>value, column=>value),); * @param array|null $foreignSelect Add a filter on foreign keys
*/ * @return array array ([0] => array (column=>value, column=>value),);
*/
public function read ($select=null, $display=null, $order=null, public function read ($select=null, $display=null, $order=null,
$whereOr=false, $foreignSelect=null) $whereOr=false, $foreignSelect=null)
{ {
@@ -882,13 +887,14 @@ class Dblayer
return $res; return $res;
} }
/** Update the key tuple with the provided data /**
* Return the number of rows modified * Update the key tuple with the provided data
* @param string|integer $updatekey The key applied on primary key to be * Return the number of rows modified
* updated * @param string|integer $updatekey The key applied on primary key to be
* @param array $data The values to be updated * updated
* @return the number of lines modified * @param array $data The values to be updated
*/ * @return integer the number of lines modified
*/
public function update ($updatekey, $data) public function update ($updatekey, $data)
{ {
if ($this->debug) echo "== Entering update\n"; if ($this->debug) echo "== Entering update\n";
@@ -1464,78 +1470,85 @@ class Dblayer
} }
/** Hook postread /**
* This hook is run after selecting the data. * Hook postread
* @param array $data the data selected by the select * This hook is run after selecting the data.
* @return array The data modified by the hook * @param array $data the data selected by the select
*/ * @return array The data modified by the hook
*/
public function hookpostread ($data) public function hookpostread ($data)
{ {
return $data; return $data;
} }
/** Hook preinsert /**
* This hook is run before inserting a new data in the database, after the * Hook preinsert
* verification * This hook is run before inserting a new data in the database, after the
* @param array $data the data to insert in the database * verification
* @return the modified data * @param array $data the data to insert in the database
*/ * @return array the modified data
*/
public function hookpreinsert ($data) public function hookpreinsert ($data)
{ {
return $data; return $data;
} }
/** Hook postinsert /**
* This hook is run after successfuly insert a new data in the database * Hook postinsert
* @param array $data the data selected by the select * This hook is run after successfuly insert a new data in the database
* @param integer $lastID the insert identifier * @param array $data the data selected by the select
* @return the modified lastID * @param integer $lastID the insert identifier
*/ * @return integer the modified lastID
*/
public function hookpostinsert ($data, $lastID) public function hookpostinsert ($data, $lastID)
{ {
return $lastID; return $lastID;
} }
/** Hook preupdate /**
* This hook is run before updating a data in the database, after the * Hook preupdate
* verification * This hook is run before updating a data in the database, after the
* @param string $updatekey the key to be modify * verification
* @param array $data the data selected by the select * @param string $updatekey the key to be modify
* @return the modified data * @param array $data the data selected by the select
*/ * @return array the modified data
*/
public function hookpreupdate ($updatekey, $data) public function hookpreupdate ($updatekey, $data)
{ {
return $data; return $data;
} }
/** Hook postupdate /**
* This hook is run after successfuly update a data in the database * Hook postupdate
* @param string $updatekey the key which was modified * This hook is run after successfuly update a data in the database
* @param array $data the data selected by the select * @param string $updatekey the key which was modified
* @param integer $nbLinesUpdated The number of modified lines * @param array $data the data selected by the select
* @return the modified $nbLinesUpdated * @param integer $nbLinesUpdated The number of modified lines
*/ * @return integer the modified $nbLinesUpdated
*/
public function hookpostupdate ($updatekey, $data, $nbLinesUpdated) public function hookpostupdate ($updatekey, $data, $nbLinesUpdated)
{ {
return $nbLinesUpdated; return $nbLinesUpdated;
} }
/** Hook predelete /**
* This hook is run before deleting a data in the database * Hook predelete
* @param string $deletekey The key to be removed * This hook is run before deleting a data in the database
* @return the modified $deletekey * @param string $deletekey The key to be removed
*/ * @return string the modified $deletekey
*/
public function hookpredelete ($deletekey) public function hookpredelete ($deletekey)
{ {
return $deletekey; return $deletekey;
} }
/** Hook postdelete /**
* This hook is run after successfuly deleting a data in the database * Hook postdelete
* @param string $deletekey The removed key * This hook is run after successfuly deleting a data in the database
* @param integer $nbLinesDeleted The number of deleted lines * @param string $deletekey The removed key
* @return $nbLinesUpdated * @param integer $nbLinesDeleted The number of deleted lines
*/ * @return integer $nbLinesUpdated
*/
public function hookpostdelete ($deletekey, $nbLinesDeleted) public function hookpostdelete ($deletekey, $nbLinesDeleted)
{ {
return $nbLinesDeleted; return $nbLinesDeleted;