Skip to content

Commit

Permalink
Added in built in support for Illuminate\Database's default fetch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelnano committed Jul 28, 2015
1 parent b6fdfcb commit 0687b70
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Phpmig/Adapter/Illuminate/Database.php
Expand Up @@ -5,8 +5,10 @@
*/
namespace Phpmig\Adapter\Illuminate;

use PDO;
use \Phpmig\Migration\Migration,
\Phpmig\Adapter\AdapterInterface;
use RuntimeException;

/**
* @author Andrew Smith http://github.com/silentworks
Expand Down Expand Up @@ -36,13 +38,27 @@ public function __construct($adapter, $tableName)
*/
public function fetchAll()
{
$fetchMode = $this->adapter->connection()
->getFetchMode();

$all = $this->adapter->connection()
->table($this->tableName)
->orderBy('version')
->get();

return array_map(function($v) {
return $v['version'];
return array_map(function($v) use($fetchMode) {

switch ($fetchMode) {

case PDO::FETCH_OBJ:
return $v->version;

case PDO::FETCH_ASSOC:
return $v['version'];

default:
throw new RuntimeException("The PDO::FETCH_* constant {$fetchMode} is not supported");
}
}, $all);
}

Expand Down

0 comments on commit 0687b70

Please sign in to comment.