Skip to content

Commit 8d52496

Browse files
Merge pull request #83 from ddelnano/master
Added in built in support for Illuminate\Database's default fetch mode
2 parents b6fdfcb + 0687b70 commit 8d52496

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Phpmig/Adapter/Illuminate/Database.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*/
66
namespace Phpmig\Adapter\Illuminate;
77

8+
use PDO;
89
use \Phpmig\Migration\Migration,
910
\Phpmig\Adapter\AdapterInterface;
11+
use RuntimeException;
1012

1113
/**
1214
* @author Andrew Smith http://github.com/silentworks
@@ -36,13 +38,27 @@ public function __construct($adapter, $tableName)
3638
*/
3739
public function fetchAll()
3840
{
41+
$fetchMode = $this->adapter->connection()
42+
->getFetchMode();
43+
3944
$all = $this->adapter->connection()
4045
->table($this->tableName)
4146
->orderBy('version')
4247
->get();
4348

44-
return array_map(function($v) {
45-
return $v['version'];
49+
return array_map(function($v) use($fetchMode) {
50+
51+
switch ($fetchMode) {
52+
53+
case PDO::FETCH_OBJ:
54+
return $v->version;
55+
56+
case PDO::FETCH_ASSOC:
57+
return $v['version'];
58+
59+
default:
60+
throw new RuntimeException("The PDO::FETCH_* constant {$fetchMode} is not supported");
61+
}
4662
}, $all);
4763
}
4864

0 commit comments

Comments
 (0)