Skip to content

Commit

Permalink
Allow anonymous migration classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Feb 23, 2022
1 parent 4c28587 commit b16bb17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Database/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp($file)
return false;
}

$this->isValidScript($object);
$this->isValidScript($object, $file);

Eloquent::unguard();

Expand All @@ -52,7 +52,7 @@ public function packDown($file)
return false;
}

$this->isValidScript($object);
$this->isValidScript($object, $file);

Eloquent::unguard();

Expand All @@ -76,8 +76,11 @@ public function resolve($file)
return;
}

require_once $file;
$instance = require_once $file;

if (is_object($instance)) {
return $instance;
}
if ($class = $this->getClassFromFile($file)) {
return new $class;
}
Expand All @@ -86,7 +89,7 @@ public function resolve($file)
/**
* Checks if the object is a valid update script.
*/
protected function isValidScript($object)
protected function isValidScript($object, $file)
{
if ($object instanceof Updates\Migration) {
return true;
Expand All @@ -96,8 +99,8 @@ protected function isValidScript($object)
}

throw new Exception(sprintf(
'Database script [%s] must inherit Winter\Storm\Database\Updates\Migration or Winter\Storm\Database\Updates\Seeder classes',
get_class($object)
'Database script [%s] must define a class that inherits the "Winter\Storm\Database\Updates\Migration" or "Winter\Storm\Database\Updates\Seeder" classes',
$file
));
}

Expand Down

0 comments on commit b16bb17

Please sign in to comment.