Skip to content

Commit b16bb17

Browse files
committed
Allow anonymous migration classes
Refs: wintercms/winter#148
1 parent 4c28587 commit b16bb17

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/Database/Updater.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function setUp($file)
2525
return false;
2626
}
2727

28-
$this->isValidScript($object);
28+
$this->isValidScript($object, $file);
2929

3030
Eloquent::unguard();
3131

@@ -52,7 +52,7 @@ public function packDown($file)
5252
return false;
5353
}
5454

55-
$this->isValidScript($object);
55+
$this->isValidScript($object, $file);
5656

5757
Eloquent::unguard();
5858

@@ -76,8 +76,11 @@ public function resolve($file)
7676
return;
7777
}
7878

79-
require_once $file;
79+
$instance = require_once $file;
8080

81+
if (is_object($instance)) {
82+
return $instance;
83+
}
8184
if ($class = $this->getClassFromFile($file)) {
8285
return new $class;
8386
}
@@ -86,7 +89,7 @@ public function resolve($file)
8689
/**
8790
* Checks if the object is a valid update script.
8891
*/
89-
protected function isValidScript($object)
92+
protected function isValidScript($object, $file)
9093
{
9194
if ($object instanceof Updates\Migration) {
9295
return true;
@@ -96,8 +99,8 @@ protected function isValidScript($object)
9699
}
97100

98101
throw new Exception(sprintf(
99-
'Database script [%s] must inherit Winter\Storm\Database\Updates\Migration or Winter\Storm\Database\Updates\Seeder classes',
100-
get_class($object)
102+
'Database script [%s] must define a class that inherits the "Winter\Storm\Database\Updates\Migration" or "Winter\Storm\Database\Updates\Seeder" classes',
103+
$file
101104
));
102105
}
103106

0 commit comments

Comments
 (0)