Skip to content

Commit 1be3340

Browse files
committed
Merge branch 'release-1.2.7'
2 parents fd0933e + 4ef909e commit 1be3340

26 files changed

+683
-739
lines changed

lib/Database.php

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,62 +17,9 @@ class Database
1717
{
1818
private $_connection;
1919

20-
public function __construct(Connection $conn)
20+
public function __construct(Connection $conn = null)
2121
{
22-
$this->setConnection($conn);
23-
$this->chooseCompiler();
24-
}
25-
26-
/**
27-
* Set the compiler according to database driver.
28-
*
29-
* If no adequate compiler is found for the driver, default compiler is
30-
* used.
31-
*
32-
* @see setCompiler()
33-
* @see setDefaultCompiler()
34-
*/
35-
public function chooseCompiler()
36-
{
37-
$specificCompiler = ucfirst($this->_connection->getDriver()) . 'Compiler';
38-
$specificCompiler = 'SimpleAR\Database\Compiler\\' . $specificCompiler;
39-
40-
if (class_exists($specificCompiler)) {
41-
$this->setCompiler(new $specificCompiler);
42-
} else {
43-
$this->setDefaultCompiler();
44-
}
45-
}
46-
47-
/**
48-
* Set the connecton.
49-
*
50-
* @param Connection $conn
51-
*/
52-
public function setConnection(Connection $conn)
53-
{
54-
$this->_connection = $conn;
55-
}
56-
57-
/**
58-
* Set the compiler.
59-
*
60-
* @param Compiler $compiler
61-
*/
62-
public function setCompiler(Compiler $compiler)
63-
{
64-
$this->_compiler = $compiler;
65-
}
66-
67-
/**
68-
* Set default compiler.
69-
*
70-
* @see setCompiler()
71-
* @see Database\Compiler\BaseCompiler
72-
*/
73-
public function setDefaultCompiler()
74-
{
75-
$this->setCompiler(new BaseCompiler);
22+
$conn && $this->setConnection($conn);
7623
}
7724

7825
/**
@@ -91,19 +38,29 @@ public function expr($expression)
9138
*
9239
* @var Connection
9340
*/
94-
public function connection()
41+
public function getConnection()
9542
{
9643
return $this->_connection;
9744
}
9845

46+
/**
47+
* Set the connecton.
48+
*
49+
* @param Connection $conn
50+
*/
51+
public function setConnection(Connection $conn)
52+
{
53+
$this->_connection = $conn;
54+
}
55+
9956
/**
10057
* Return the Compiler instance.
10158
*
10259
* @var Compiler
10360
*/
104-
public function compiler()
61+
public function getCompiler()
10562
{
106-
return $this->_compiler;
63+
return $this->getConnection()->getCompiler();
10764
}
10865

10966
/**

lib/Database/Builder.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,29 @@ public function convertAttributesToColumns($attributes, Table $table)
208208
/**
209209
* Add query value to value list.
210210
*
211+
* If $component is not given, it expects $value to be an array of
212+
* components' values.
213+
*
211214
* @param mixed $value The value to add to the value list.
215+
* @param string $component The component type ('set', 'where'...).
216+
*
212217
* @return void
213218
*/
214-
public function addValueToQuery($value)
219+
public function addValueToQuery($value, $component = '')
215220
{
216-
if (! $value instanceof Expression)
221+
if ($component)
217222
{
218-
$this->_values[] = $value;
223+
if (! $value instanceof Expression)
224+
{
225+
$this->_values[$component][] = $value;
226+
}
227+
}
228+
else
229+
{
230+
foreach ($value as $component => $values)
231+
{
232+
$this->addValueToQuery($values, $component);
233+
}
219234
}
220235
}
221236

lib/Database/Builder/InsertBuilder.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ class InsertBuilder extends Builder
1212
'values',
1313
);
1414

15-
public function getValues()
16-
{
17-
$values = $this->_components['values'];
18-
19-
if (is_array($values[0]))
20-
{
21-
// We also need to flatten value array.
22-
return call_user_func_array('array_merge', $values);
23-
}
24-
25-
return $values;
26-
}
27-
2815
public function useRootModel($class)
2916
{
3017
parent::useRootModel($class);
@@ -52,5 +39,6 @@ protected function _buildFields(array $fields)
5239
protected function _buildValues(array $values)
5340
{
5441
$this->_components['values'] = $values;
42+
$this->addValueToQuery($values, 'values');
5543
}
5644
}

lib/Database/Builder/UpdateBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function _buildSet(array $sets)
7575
$this->_components['set'][] = compact('tableAlias', 'column', 'value');
7676

7777
// One other task to do: move value over one place.
78-
$this->addValueToQuery($value);
78+
$this->addValueToQuery($value, 'set');
7979
}
8080
}
8181
}

0 commit comments

Comments
 (0)