Docblock fixes and more dependency injection

This commit is contained in:
Timothy Warren 2014-04-23 15:53:16 -04:00
parent 0a64edd453
commit aa5aa8eb97
12 changed files with 141 additions and 98 deletions

View File

@ -36,7 +36,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
protected $statement;
/**
* Character to escape indentifiers
* Character to escape identifiers
* @var string
*/
protected $escape_char = '"';
@ -100,6 +100,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
/**
* Allow invoke to work on table object
*
* @codeCoverageIgnore
* @param string $name
* @param array $args
* @return mixed
@ -120,6 +121,30 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
// ! Concrete functions that can be overridden in child classes
// --------------------------------------------------------------------------
/**
* Get the SQL class for the current driver
*
* @return SQL_Interface
*/
public function get_sql()
{
return $this->sql;
}
// --------------------------------------------------------------------------
/**
* Get the Util class for the current driver
*
* @return Abstract_Util
*/
public function get_util()
{
return $this->util;
}
// --------------------------------------------------------------------------
/**
* Simplifies prepared statements for database queries
*
@ -193,7 +218,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
// before quoting it
if ( ! empty($this->table_prefix))
{
// Split indentifier by period, will split into:
// Split identifier by period, will split into:
// database.schema.table OR
// schema.table OR
// database.table OR
@ -436,7 +461,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
*/
public function get_columns($table)
{
return $this->driver_query($this->sql->column_list($this->prefix_table($table)), FALSE);
return $this->driver_query($this->get_sql()->column_list($this->prefix_table($table)), FALSE);
}
// --------------------------------------------------------------------------
@ -449,7 +474,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
*/
public function get_fks($table)
{
return $this->driver_query($this->sql->fk_list($table), FALSE);
return $this->driver_query($this->get_sql()->fk_list($table), FALSE);
}
// --------------------------------------------------------------------------
@ -462,7 +487,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
*/
public function get_indexes($table)
{
return $this->driver_query($this->sql->index_list($this->prefix_table($table)), FALSE);
return $this->driver_query($this->get_sql()->index_list($this->prefix_table($table)), FALSE);
}
// --------------------------------------------------------------------------
@ -491,7 +516,7 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface {
// Call the appropriate method, if it exists
if (is_string($query) && method_exists($this->sql, $query))
{
$query = $this->sql->$query();
$query = $this->get_sql()->$query();
}
// Return if the values are returned instead of a query,

View File

@ -28,7 +28,7 @@ abstract class Abstract_SQL implements SQL_Interface {
*
* @param string $sql
* @param int $limit
* @param int $offset
* @param int|bool $offset
* @return string
*/
public function limit($sql, $limit, $offset=FALSE)

View File

@ -117,6 +117,7 @@ final class Connection_Manager {
}
else
{
// You should actually connect before trying to get a connection...
throw new \InvalidArgumentException("The specified connection does not exist");
}
}
@ -128,7 +129,6 @@ final class Connection_Manager {
*
* @param \ArrayObject $params
* @return Query_Builder
* @throws BadConnectionException
*/
public function connect(\ArrayObject $params)
{
@ -147,8 +147,9 @@ final class Connection_Manager {
$db->table_prefix = $params->prefix;
}
// Create the Query Builder object
$conn = new Query_Builder($db);
// Create Query Builder object
$conn = new Query_Builder($db, new Query_Parser($db));
// Save it for later
if (isset($params->alias))

View File

@ -30,7 +30,6 @@ interface Driver_Interface {
* @param string $username
* @param string $password
* @param array $driver_options
* @return void
*/
public function __construct($dsn, $username=NULL, $password=NULL, array $driver_options = array());
@ -140,5 +139,19 @@ interface Driver_Interface {
* @return \PDOStatement
*/
public function prepare_execute($sql, $params);
/**
* Get the SQL class for the current driver
*
* @return SQL_Interface
*/
public function get_sql();
/**
* Get the Util class for the current driver
*
* @return Abstract_Util
*/
public function get_util();
}
// End of driver_interface.php

View File

@ -100,7 +100,7 @@ class Query_Builder implements Query_Builder_Interface {
/**
* Value for limit string
* @var type string
* @var string
*/
protected $limit;
@ -162,14 +162,14 @@ class Query_Builder implements Query_Builder_Interface {
protected $parser;
/**
* Alias to $this->db->util
* @var DB_Util
* Alias to driver util class
* @var \Query\Driver\Abstract_Util
*/
public $util;
/**
* Alias to $this->db->sql
* @var SQL_Interface
* Alias to driver sql class
* @var \Query\Driver\SQL_Interface
*/
public $sql;
@ -181,19 +181,19 @@ class Query_Builder implements Query_Builder_Interface {
* Constructor
*
* @param \Query\Driver\Driver_Interface $db
* @param Query_Parser $parser
*/
public function __construct(Driver_Interface $db)
public function __construct(Driver_Interface $db, Query_Parser $parser)
{
// Inject driver and parser
$this->db = $db;
// Instantiate the Query Parser
$this->parser = new Query_Parser($this);
$this->parser = $parser;
$this->queries['total_time'] = 0;
// Make things just slightly shorter
$this->sql = $this->db->sql;
$this->util = $this->db->util;
// Alias driver sql and util classes
$this->sql = $this->db->get_sql();
$this->util = $this->db->get_util();
}
// --------------------------------------------------------------------------
@ -215,7 +215,7 @@ class Query_Builder implements Query_Builder_Interface {
* Method to simplify select_ methods
*
* @param string $field
* @param string $as
* @param string|bool $as
* @return string
*/
protected function _select($field, $as = FALSE)
@ -295,7 +295,7 @@ class Query_Builder implements Query_Builder_Interface {
* Selects the minimum value of a field from a query
*
* @param string $field
* @param string $as
* @param string|bool $as
* @return Query_Builder
*/
public function select_min($field, $as=FALSE)
@ -311,7 +311,7 @@ class Query_Builder implements Query_Builder_Interface {
* Selects the average value of a field from a query
*
* @param string $field
* @param string $as
* @param string|bool $as
* @return Query_Builder
*/
public function select_avg($field, $as=FALSE)
@ -327,7 +327,7 @@ class Query_Builder implements Query_Builder_Interface {
* Selects the sum of a field from a query
*
* @param string $field
* @param string $as
* @param string|bool $as
* @return Query_Builder
*/
public function select_sum($field, $as=FALSE)
@ -975,7 +975,7 @@ class Query_Builder implements Query_Builder_Interface {
* @param $table
* @param int|bool $limit
* @param int|bool $offset
* @return PDOStatement
* @return \PDOStatement
*/
public function get($table='', $limit=FALSE, $offset=FALSE)
{
@ -986,7 +986,7 @@ class Query_Builder implements Query_Builder_Interface {
}
// Set the limit, if it exists
if ($limit !== FALSE)
if (is_int($limit))
{
$this->limit($limit, $offset);
}
@ -997,13 +997,13 @@ class Query_Builder implements Query_Builder_Interface {
// --------------------------------------------------------------------------
/**
* Convience method for get() with a where clause
* Convenience method for get() with a where clause
*
* @param string $table
* @param array $where
* @param int $limit
* @param int $offset
* @return PDOStatement
* @param int|bool $limit
* @param int|bool $offset
* @return \PDOStatement
*/
public function get_where($table, $where=array(), $limit=FALSE, $offset=FALSE)
{
@ -1061,7 +1061,7 @@ class Query_Builder implements Query_Builder_Interface {
*
* @param string $table
* @param mixed $data
* @return PDOStatement
* @return \PDOStatement
*/
public function insert($table, $data=array())
{
@ -1081,7 +1081,7 @@ class Query_Builder implements Query_Builder_Interface {
*
* @param string $table
* @param array $data
* @return PDOStatement
* @return \PDOStatement
*/
public function insert_batch($table, $data=array())
{
@ -1100,7 +1100,7 @@ class Query_Builder implements Query_Builder_Interface {
*
* @param string $table
* @param mixed $data
* @return PDOStatement
* @return \PDOStatement
*/
public function update($table, $data=array())
{
@ -1120,7 +1120,7 @@ class Query_Builder implements Query_Builder_Interface {
*
* @param string $table
* @param mixed $where
* @return PDOStatement
* @return \PDOStatement
*/
public function delete($table, $where='')
{
@ -1143,7 +1143,7 @@ class Query_Builder implements Query_Builder_Interface {
* @param string $type
* @param string $table
* @param bool $reset
* @resturn string
* @return string
*/
protected function _get_compile($type, $table, $reset)
{
@ -1271,7 +1271,7 @@ class Query_Builder implements Query_Builder_Interface {
* @param string $table
* @param string $sql
* @param array|null $vals
* @return PDOStatement
* @return \PDOStatement
*/
protected function _run($type, $table, $sql=NULL, $vals=NULL)
{
@ -1311,7 +1311,7 @@ class Query_Builder implements Query_Builder_Interface {
* @param string $name
* @param array $params
* @return mixed
* @throws BadMethodCallException
* @throws \BadMethodCallException
*/
public function __call($name, $params)
{

View File

@ -56,9 +56,9 @@ class Query_Parser {
/**
* Constructor/entry point into parser
*
* @param \Query\Query_Builder $db
* @param Query_Builder $db
*/
public function __construct(\Query\Query_Builder $db)
public function __construct(\Query\Driver\Driver_Interface $db)
{
$this->db = $db;
}
@ -66,9 +66,10 @@ class Query_Parser {
// --------------------------------------------------------------------------
/**
* Public parser method for seting the parse string
* Public parser method for setting the parse string
*
* @param string $sql
* @return array
*/
protected function parse_join($sql)
{
@ -112,6 +113,8 @@ class Query_Parser {
return implode('', $parts['combined']);
}
// --------------------------------------------------------------------------
/**
* Returns a more useful match array
*

View File

@ -57,7 +57,8 @@ class Firebird_Result extends \PDOStatement {
* the query
*
* @param resource $link
* @param [\Query\Driver\Firebird] $db
* @param \Query\Driver\Firebird|null $db
* @return void
*/
public function __construct($link, Driver_Interface $db = NULL)
{

View File

@ -28,7 +28,7 @@ class Firebird_SQL extends Abstract_SQL {
*
* @param string $sql
* @param int $limit
* @param int $offset
* @param int|bool $offset
* @return string
*/
public function limit($sql, $limit, $offset=FALSE)

View File

@ -28,7 +28,7 @@ namespace Query\Driver;
class Firebird_Util extends Abstract_Util {
/**
* Convienience public function to generate sql for creating a db table
* Convenience public function to generate sql for creating a db table
*
* @deprecated Use the table builder class instead
* @param string $name

View File

@ -153,13 +153,6 @@ abstract class QBTest extends Query_TestCase {
$this->assertIsA($query, 'PDOStatement');
}
// --------------------------------------------------------------------------
public function testGetViews()
{
$this->assertTrue(is_array($this->db->get_views()));
}
// --------------------------------------------------------------------------
// ! Select tests
// --------------------------------------------------------------------------

View File

@ -94,5 +94,12 @@ abstract class DBTest extends Query_TestCase {
$this->assertTrue(is_array($keys));
}
// --------------------------------------------------------------------------
public function testGetViews()
{
$this->assertTrue(is_array($this->db->get_views()));
}
}
// End of db_test.php

Binary file not shown.