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

View File

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