1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

used variadics (BC break: signatures are changed)

This commit is contained in:
David Grudl
2017-06-09 17:27:06 +02:00
parent 24180c76bd
commit 68e0aef469
2 changed files with 34 additions and 51 deletions

View File

@@ -205,38 +205,35 @@ class Connection
/**
* Generates (translates) and executes SQL query.
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Result|int result set or number of affected rows
* @throws Exception
*/
final public function query($args)
final public function query(...$args)
{
$args = func_get_args();
return $this->nativeQuery($this->translateArgs($args));
}
/**
* Generates SQL query.
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return string
* @throws Exception
*/
final public function translate($args)
final public function translate(...$args)
{
$args = func_get_args();
return $this->translateArgs($args);
}
/**
* Generates and prints SQL query.
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return bool
*/
final public function test($args)
final public function test(...$args)
{
$args = func_get_args();
try {
Helpers::dump($this->translateArgs($args));
return TRUE;
@@ -254,13 +251,12 @@ class Connection
/**
* Generates (translates) and returns SQL query as DataSource.
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return DataSource
* @throws Exception
*/
final public function dataSource($args)
final public function dataSource(...$args)
{
$args = func_get_args();
return new DataSource($this->translateArgs($args), $this);
}
@@ -457,10 +453,9 @@ class Connection
* @param mixed column name
* @return Fluent
*/
public function select($args)
public function select(...$args)
{
$args = func_get_args();
return $this->command()->__call('select', $args);
return $this->command()->select(...$args);
}
@@ -535,52 +530,48 @@ class Connection
/**
* Executes SQL query and fetch result - shortcut for query() & fetch().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Row|FALSE
* @throws Exception
*/
public function fetch($args)
public function fetch(...$args)
{
$args = func_get_args();
return $this->query($args)->fetch();
}
/**
* Executes SQL query and fetch results - shortcut for query() & fetchAll().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Row[]
* @throws Exception
*/
public function fetchAll($args)
public function fetchAll(...$args)
{
$args = func_get_args();
return $this->query($args)->fetchAll();
}
/**
* Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return mixed
* @throws Exception
*/
public function fetchSingle($args)
public function fetchSingle(...$args)
{
$args = func_get_args();
return $this->query($args)->fetchSingle();
}
/**
* Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return array
* @throws Exception
*/
public function fetchPairs($args)
public function fetchPairs(...$args)
{
$args = func_get_args();
return $this->query($args)->fetchPairs();
}

View File

@@ -136,13 +136,12 @@ class dibi
/**
* Generates and executes SQL query - Monostate for Dibi\Connection::query().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Dibi\Result|int result set or number of affected rows
* @throws Dibi\Exception
*/
public static function query($args)
public static function query(...$args)
{
$args = func_get_args();
return self::getConnection()->query($args);
}
@@ -160,76 +159,70 @@ class dibi
/**
* Generates and prints SQL query - Monostate for Dibi\Connection::test().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return bool
*/
public static function test($args)
public static function test(...$args)
{
$args = func_get_args();
return self::getConnection()->test($args);
}
/**
* Generates and returns SQL query as DataSource - Monostate for Dibi\Connection::test().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Dibi\DataSource
*/
public static function dataSource($args)
public static function dataSource(...$args)
{
$args = func_get_args();
return self::getConnection()->dataSource($args);
}
/**
* Executes SQL query and fetch result - Monostate for Dibi\Connection::query() & fetch().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Dibi\Row
* @throws Dibi\Exception
*/
public static function fetch($args)
public static function fetch(...$args)
{
$args = func_get_args();
return self::getConnection()->query($args)->fetch();
}
/**
* Executes SQL query and fetch results - Monostate for Dibi\Connection::query() & fetchAll().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return Dibi\Row[]
* @throws Dibi\Exception
*/
public static function fetchAll($args)
public static function fetchAll(...$args)
{
$args = func_get_args();
return self::getConnection()->query($args)->fetchAll();
}
/**
* Executes SQL query and fetch first column - Monostate for Dibi\Connection::query() & fetchSingle().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return mixed
* @throws Dibi\Exception
*/
public static function fetchSingle($args)
public static function fetchSingle(...$args)
{
$args = func_get_args();
return self::getConnection()->query($args)->fetchSingle();
}
/**
* Executes SQL query and fetch pairs - Monostate for Dibi\Connection::query() & fetchPairs().
* @param array|mixed one or more arguments
* @param mixed one or more arguments
* @return array
* @throws Dibi\Exception
*/
public static function fetchPairs($args)
public static function fetchPairs(...$args)
{
$args = func_get_args();
return self::getConnection()->query($args)->fetchPairs();
}
@@ -355,10 +348,9 @@ class dibi
* @param mixed column name
* @return Dibi\Fluent
*/
public static function select($args)
public static function select(...$args)
{
$args = func_get_args();
return call_user_func_array([self::getConnection(), 'select'], $args);
return self::getConnection()->select(...$args);
}