mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 05:37:39 +02:00
ArrayObject -> Traversable & iterator_to_array
This commit is contained in:
@@ -204,8 +204,8 @@ class dibi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new DibiConnection object and connects it to specified database.
|
* Creates a new DibiConnection object and connects it to specified database.
|
||||||
* @param array|string|ArrayObject connection parameters
|
* @param mixed connection parameters
|
||||||
* @param string connection name
|
* @param string connection name
|
||||||
* @return DibiConnection
|
* @return DibiConnection
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
|
@@ -44,8 +44,8 @@ class DibiConnection extends DibiObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates object and (optionally) connects to a database.
|
* Creates object and (optionally) connects to a database.
|
||||||
* @param array|string|ArrayObject connection parameters
|
* @param mixed connection parameters
|
||||||
* @param string connection name
|
* @param string connection name
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
public function __construct($config, $name = NULL)
|
public function __construct($config, $name = NULL)
|
||||||
@@ -58,7 +58,7 @@ class DibiConnection extends DibiObject
|
|||||||
$config = iterator_to_array($config);
|
$config = iterator_to_array($config);
|
||||||
|
|
||||||
} elseif (!is_array($config)) {
|
} elseif (!is_array($config)) {
|
||||||
throw new InvalidArgumentException('Configuration must be array, string or ArrayObject.');
|
throw new InvalidArgumentException('Configuration must be array, string or object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
self::alias($config, 'username', 'user');
|
self::alias($config, 'username', 'user');
|
||||||
@@ -553,8 +553,8 @@ class DibiConnection extends DibiObject
|
|||||||
*/
|
*/
|
||||||
public function update($table, $args)
|
public function update($table, $args)
|
||||||
{
|
{
|
||||||
if (!(is_array($args) || $args instanceof ArrayObject)) {
|
if (!(is_array($args) || $args instanceof Traversable)) {
|
||||||
throw new InvalidArgumentException('Arguments must be array or ArrayObject.');
|
throw new InvalidArgumentException('Arguments must be array or Traversable.');
|
||||||
}
|
}
|
||||||
return $this->command()->update('%n', $table)->set($args);
|
return $this->command()->update('%n', $table)->set($args);
|
||||||
}
|
}
|
||||||
@@ -568,10 +568,10 @@ class DibiConnection extends DibiObject
|
|||||||
*/
|
*/
|
||||||
public function insert($table, $args)
|
public function insert($table, $args)
|
||||||
{
|
{
|
||||||
if ($args instanceof ArrayObject) {
|
if ($args instanceof Traversable) {
|
||||||
$args = (array) $args;
|
$args = iterator_to_array($args);
|
||||||
} elseif (!is_array($args)) {
|
} elseif (!is_array($args)) {
|
||||||
throw new InvalidArgumentException('Arguments must be array or ArrayObject.');
|
throw new InvalidArgumentException('Arguments must be array or Traversable.');
|
||||||
}
|
}
|
||||||
return $this->command()->insert()
|
return $this->command()->insert()
|
||||||
->into('%n', $table, '(%n)', array_keys($args))->values('%l', $args);
|
->into('%n', $table, '(%n)', array_keys($args))->values('%l', $args);
|
||||||
|
@@ -132,7 +132,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
} elseif ($arg instanceof self) {
|
} elseif ($arg instanceof self) {
|
||||||
$args = array_merge(array('('), $arg->_export(), array(')'));
|
$args = array_merge(array('('), $arg->_export(), array(')'));
|
||||||
|
|
||||||
} elseif (is_array($arg) || $arg instanceof ArrayObject) { // any array
|
} elseif (is_array($arg) || $arg instanceof Traversable) { // any array
|
||||||
if (isset(self::$modifiers[$clause])) {
|
if (isset(self::$modifiers[$clause])) {
|
||||||
$args = array(self::$modifiers[$clause], $arg);
|
$args = array(self::$modifiers[$clause], $arg);
|
||||||
|
|
||||||
|
@@ -134,8 +134,8 @@ final class DibiTranslator extends DibiObject
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($arg instanceof ArrayObject) {
|
if ($arg instanceof Traversable) {
|
||||||
$arg = (array) $arg;
|
$arg = iterator_to_array($arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($arg)) {
|
if (is_array($arg)) {
|
||||||
@@ -192,8 +192,8 @@ final class DibiTranslator extends DibiObject
|
|||||||
public function formatValue($value, $modifier)
|
public function formatValue($value, $modifier)
|
||||||
{
|
{
|
||||||
// array processing (with or without modifier)
|
// array processing (with or without modifier)
|
||||||
if ($value instanceof ArrayObject) {
|
if ($value instanceof Traversable) {
|
||||||
$value = (array) $value;
|
$value = iterator_to_array($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
|
Reference in New Issue
Block a user