Skip to content

Commit

Permalink
Merge pull request #83 from ddelnano/master
Browse files Browse the repository at this point in the history
Added in built in support for Illuminate\Database's default fetch mode
  • Loading branch information
davedevelopment committed Jul 29, 2015
2 parents b6fdfcb + 0687b70 commit 8d52496
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Phpmig/Adapter/Illuminate/Database.php
Original file line number Diff line number Diff line change
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 8d52496

Please sign in to comment.