1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

- DibiConnection: insert() and update() accepts ArrayObject

This commit is contained in:
David Grudl
2009-06-19 11:28:42 +00:00
parent 74178a5596
commit e52cee8cbc
3 changed files with 13 additions and 5 deletions

View File

@@ -536,7 +536,7 @@ class dibi
* @param array * @param array
* @return DibiFluent * @return DibiFluent
*/ */
public static function update($table, array $args) public static function update($table, $args)
{ {
return self::getConnection()->update($table, $args); return self::getConnection()->update($table, $args);
} }
@@ -548,7 +548,7 @@ class dibi
* @param array * @param array
* @return DibiFluent * @return DibiFluent
*/ */
public static function insert($table, array $args) public static function insert($table, $args)
{ {
return self::getConnection()->insert($table, $args); return self::getConnection()->insert($table, $args);
} }

View File

@@ -581,8 +581,11 @@ class DibiConnection extends DibiObject
* @param array * @param array
* @return DibiFluent * @return DibiFluent
*/ */
public function update($table, array $args) public function update($table, $args)
{ {
if (!(is_array($args) || $args instanceof ArrayObject)) {
throw new InvalidArgumentException('Arguments must be array or ArrayObject.');
}
return $this->command()->update('%n', $table)->set($args); return $this->command()->update('%n', $table)->set($args);
} }
@@ -593,8 +596,13 @@ class DibiConnection extends DibiObject
* @param array * @param array
* @return DibiFluent * @return DibiFluent
*/ */
public function insert($table, array $args) public function insert($table, $args)
{ {
if ($args instanceof ArrayObject) {
$args = (array) $args;
} elseif (!is_array($args)) {
throw new InvalidArgumentException('Arguments must be array or ArrayObject.');
}
return $this->command()->insert() return $this->command()->insert()
->into('%n', $table, '(%n)', array_keys($args))->values('%l', array_values($args)); ->into('%n', $table, '(%n)', array_keys($args))->values('%l', array_values($args));
} }

View File

@@ -126,7 +126,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)) { // any array } elseif (is_array($arg) || $arg instanceof ArrayObject) { // any array
if (isset(self::$modifiers[$clause])) { if (isset(self::$modifiers[$clause])) {
$args = array(self::$modifiers[$clause], $arg); $args = array(self::$modifiers[$clause], $arg);