Skip to content

Commit

Permalink
Removing global reference to $db from pudlOrm::collect()
Browse files Browse the repository at this point in the history
  • Loading branch information
darkain committed Oct 16, 2018
1 parent cfbc43c commit d0e2fdc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions pudlOrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ public static function select(/* ...$selex */) {
////////////////////////////////////////////////////////////////////////////
//GET A COLLECTION OF OBJECTS
////////////////////////////////////////////////////////////////////////////
public static function collect(/* ...$selex */) {
global $db; //TODO: REMOVE GLOBAL REFERENCE

public static function collect($db /*, ...$selex */) {
if (static::collector === __CLASS__) {
throw new pudlException(
$db,
Expand All @@ -180,6 +178,7 @@ public static function collect(/* ...$selex */) {
}

$args = func_get_args();
array_shift($args);
array_unshift($args, static::schema());

$collector = static::collector;
Expand Down Expand Up @@ -221,7 +220,7 @@ public static function collection($db, $items /*, ...$selex */) {
}
}

$args[0] = ['clause' => [pudl::column(
$args[1] = ['clause' => [pudl::column(
[static::prefix, static::column],
$items
)]];
Expand Down
4 changes: 2 additions & 2 deletions test/collection.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class test_orm extends pudlOrm {


$db->string();
test_orm::collect();
test_orm::collect($db);
pudlTest($db, 'SELECT * FROM `pudl`');



$db->string();
test_orm::collect(['clause'=>['x'=>1], 'limit'=>10]);
test_orm::collect($db, ['clause'=>['x'=>1], 'limit'=>10]);
pudlTest($db, 'SELECT * FROM `pudl` WHERE (`x`=1) LIMIT 10');


Expand Down

0 comments on commit d0e2fdc

Please sign in to comment.