Remove __call method from util classes
This commit is contained in:
parent
1f744088f2
commit
ff77cea041
@ -43,19 +43,15 @@ abstract class Abstract_Util {
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Enable calling driver methods
|
||||
* Get the driver object for the current connection
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
* @return Driver_Interface
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
public function get_driver()
|
||||
{
|
||||
return call_user_func_array(array($this->conn, $method), $args);
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ! Abstract Methods
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -70,8 +66,6 @@ abstract class Abstract_Util {
|
||||
*/
|
||||
public function create_table($name, $fields, array $constraints=array(), $if_not_exists=TRUE)
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
$exists_str = ($if_not_exists) ? ' IF NOT EXISTS ' : ' ';
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
@ -89,7 +83,7 @@ abstract class Abstract_Util {
|
||||
$columns = array();
|
||||
foreach($column_array as $n => $props)
|
||||
{
|
||||
$str = $this->quote_ident($n);
|
||||
$str = $this->get_driver()->quote_ident($n);
|
||||
$str .= (isset($props['type'])) ? " {$props['type']}" : "";
|
||||
$str .= (isset($props['constraint'])) ? " {$props['constraint']}" : "";
|
||||
|
||||
@ -97,7 +91,7 @@ abstract class Abstract_Util {
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = 'CREATE TABLE'.$exists_str.$this->quote_table($name).' (';
|
||||
$sql = 'CREATE TABLE'.$exists_str.$this->get_driver()->quote_table($name).' (';
|
||||
$sql .= implode(', ', $columns);
|
||||
$sql .= ')';
|
||||
|
||||
@ -114,9 +108,12 @@ abstract class Abstract_Util {
|
||||
*/
|
||||
public function delete_table($name)
|
||||
{
|
||||
return 'DROP TABLE IF EXISTS '.$this->quote_table($name);
|
||||
return 'DROP TABLE IF EXISTS '.$this->get_driver()->quote_table($name);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ! Abstract Methods
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -115,6 +115,13 @@ interface Driver_Interface {
|
||||
*/
|
||||
public function get_tables();
|
||||
|
||||
/**
|
||||
* Return list of dbs for the current connection, if possible
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_dbs();
|
||||
|
||||
/**
|
||||
* Surrounds the string with the databases identifier escape characters
|
||||
*
|
||||
@ -153,5 +160,14 @@ interface Driver_Interface {
|
||||
* @return Abstract_Util
|
||||
*/
|
||||
public function get_util();
|
||||
|
||||
/**
|
||||
* Method to simplify retrieving db results for meta-data queries
|
||||
*
|
||||
* @param string|array|null $query
|
||||
* @param bool $filtered_index
|
||||
* @return array
|
||||
*/
|
||||
public function driver_query($query, $filtered_index=TRUE);
|
||||
}
|
||||
// End of driver_interface.php
|
||||
|
@ -20,10 +20,6 @@ namespace Query\Driver;
|
||||
*
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
* @method array get_system_tables()
|
||||
* @method array get_tables()
|
||||
* @method object query(string $sql)
|
||||
* @method resource get_service()
|
||||
*/
|
||||
class Firebird_Util extends Abstract_Util {
|
||||
|
||||
@ -50,7 +46,7 @@ class Firebird_Util extends Abstract_Util {
|
||||
*/
|
||||
public function delete_table($name)
|
||||
{
|
||||
return 'DROP TABLE '.$this->quote_table($name);
|
||||
return 'DROP TABLE '.$this->get_driver()->quote_table($name);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -65,7 +61,7 @@ class Firebird_Util extends Abstract_Util {
|
||||
public function backup_structure()
|
||||
{
|
||||
list($db_path, $new_file) = func_get_args();
|
||||
return ibase_backup($this->get_service(), $db_path, $new_file, \IBASE_BKP_METADATA_ONLY);
|
||||
return ibase_backup($this->get_driver()->get_service(), $db_path, $new_file, \IBASE_BKP_METADATA_ONLY);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -81,13 +77,10 @@ class Firebird_Util extends Abstract_Util {
|
||||
public function backup_data($exclude=array(), $system_tables=FALSE)
|
||||
{
|
||||
// Determine which tables to use
|
||||
$tables = $this->get_driver()->get_tables();
|
||||
if($system_tables == TRUE)
|
||||
{
|
||||
$tables = array_merge($this->get_system_tables(), $this->get_tables());
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables = $this->get_tables();
|
||||
$tables = array_merge($tables, $this->get_driver()->get_system_tables());
|
||||
}
|
||||
|
||||
// Filter out the tables you don't want
|
||||
@ -102,7 +95,7 @@ class Firebird_Util extends Abstract_Util {
|
||||
foreach($tables as $t)
|
||||
{
|
||||
$sql = 'SELECT * FROM "'.trim($t).'"';
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Don't add to the file if the table is empty
|
||||
@ -121,7 +114,7 @@ class Firebird_Util extends Abstract_Util {
|
||||
// Quote values as needed by type
|
||||
if(stripos($t, 'RDB$') === FALSE)
|
||||
{
|
||||
$row = array_map(array(&$this, 'quote'), $row);
|
||||
$row = array_map(array($this->get_driver(), 'quote'), $row);
|
||||
$row = array_map('trim', $row);
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,6 @@ namespace Query\Driver;
|
||||
*
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
* @method array get_dbs()
|
||||
* @method mixed driver_query(string $sql, bool $filtered_index=TRUE)
|
||||
* @method array get_system_tables()
|
||||
* @method array get_tables()
|
||||
* @method mixed query(string $sql)
|
||||
* @method string quote(string $str)
|
||||
*/
|
||||
class MySQL_Util extends Abstract_Util {
|
||||
|
||||
@ -39,7 +33,7 @@ class MySQL_Util extends Abstract_Util {
|
||||
$string = array();
|
||||
|
||||
// Get databases
|
||||
$dbs = $this->get_dbs();
|
||||
$dbs = $this->get_driver()->get_dbs();
|
||||
|
||||
foreach($dbs as &$d)
|
||||
{
|
||||
@ -47,11 +41,11 @@ class MySQL_Util extends Abstract_Util {
|
||||
if ($d == 'mysql') continue;
|
||||
|
||||
// Get the list of tables
|
||||
$tables = $this->driver_query("SHOW TABLES FROM `{$d}`", TRUE);
|
||||
$tables = $this->get_driver()->driver_query("SHOW TABLES FROM `{$d}`", TRUE);
|
||||
|
||||
foreach($tables as $table)
|
||||
{
|
||||
$array = $this->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE);
|
||||
$array = $this->get_driver()->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE);
|
||||
$row = current($array);
|
||||
|
||||
if ( ! isset($row['Create Table'])) continue;
|
||||
@ -74,7 +68,7 @@ class MySQL_Util extends Abstract_Util {
|
||||
*/
|
||||
public function backup_data($exclude=array())
|
||||
{
|
||||
$tables = $this->get_tables();
|
||||
$tables = $this->get_driver()->get_tables();
|
||||
|
||||
// Filter out the tables you don't want
|
||||
if( ! empty($exclude))
|
||||
@ -88,7 +82,7 @@ class MySQL_Util extends Abstract_Util {
|
||||
foreach($tables as $t)
|
||||
{
|
||||
$sql = "SELECT * FROM `{$t}`";
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$rows = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Skip empty tables
|
||||
@ -107,7 +101,7 @@ class MySQL_Util extends Abstract_Util {
|
||||
// Workaround for Quercus
|
||||
foreach($row as &$r)
|
||||
{
|
||||
$r = $this->quote($r);
|
||||
$r = $this->get_driver()->quote($r);
|
||||
}
|
||||
$row = array_map('trim', $row);
|
||||
|
||||
|
@ -20,8 +20,6 @@ namespace Query\Driver;
|
||||
*
|
||||
* @package Query
|
||||
* @subpackage Drivers
|
||||
* @method mixed query(string $sql)
|
||||
* @method array get_tables()
|
||||
*/
|
||||
class PgSQL_Util extends Abstract_Util {
|
||||
|
||||
@ -46,7 +44,7 @@ class PgSQL_Util extends Abstract_Util {
|
||||
*/
|
||||
public function backup_data($exclude=array())
|
||||
{
|
||||
$tables = $this->get_tables();
|
||||
$tables = $this->get_driver()->get_tables();
|
||||
|
||||
// Filter out the tables you don't want
|
||||
if( ! empty($exclude))
|
||||
@ -60,7 +58,7 @@ class PgSQL_Util extends Abstract_Util {
|
||||
foreach($tables as $t)
|
||||
{
|
||||
$sql = 'SELECT * FROM "'.trim($t).'"';
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Don't add to the file if the table is empty
|
||||
@ -79,7 +77,7 @@ class PgSQL_Util extends Abstract_Util {
|
||||
$row = array_values($row);
|
||||
|
||||
// Quote values as needed by type
|
||||
$row = array_map(array(&$this, 'quote'), $row);
|
||||
$row = array_map(array($this->get_driver(), 'quote'), $row);
|
||||
$row = array_map('trim', $row);
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ class SQLite_Util extends Abstract_Util {
|
||||
$sql .= " AND \"name\" NOT IN('".implode("','", $excluded)."')";
|
||||
}
|
||||
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$result = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
unset($res);
|
||||
@ -54,7 +54,7 @@ class SQLite_Util extends Abstract_Util {
|
||||
foreach($result as $r)
|
||||
{
|
||||
$sql = 'SELECT * FROM "'.$r['name'].'"';
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
unset($res);
|
||||
@ -75,7 +75,7 @@ class SQLite_Util extends Abstract_Util {
|
||||
// Quote values as needed by type
|
||||
for($i=0, $icount=count($row); $i<$icount; $i++)
|
||||
{
|
||||
$row[$i] = (is_numeric($row[$i])) ? $row[$i] : $this->quote($row[$i]);
|
||||
$row[$i] = (is_numeric($row[$i])) ? $row[$i] : $this->get_driver()->quote($row[$i]);
|
||||
}
|
||||
|
||||
$row_string = 'INSERT INTO "'.$r['name'].'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');';
|
||||
@ -104,7 +104,7 @@ class SQLite_Util extends Abstract_Util {
|
||||
{
|
||||
// Fairly easy for SQLite...just query the master table
|
||||
$sql = 'SELECT "sql" FROM "sqlite_master"';
|
||||
$res = $this->query($sql);
|
||||
$res = $this->get_driver()->query($sql);
|
||||
$result = $res->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$sql_array = array();
|
||||
|
Loading…
Reference in New Issue
Block a user