Skip to content

Commit

Permalink
Allow running same path twice in same instance
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Mar 11, 2023
1 parent 3e5fd6b commit 9534eaa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Database/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class Updater
{
/**
* @var array requiredPathCache paths that have already been required.
*/
protected static $requiredPathCache = [];

/**
* setUp a migration or seed file.
*/
Expand Down Expand Up @@ -80,9 +85,15 @@ public function resolve(string $path)
return new $class;
}

$migration = require $path;
$migration = static::$requiredPathCache[$path] ??= require $path;

if (is_object($migration)) {
return method_exists($migration, '__construct')
? require $path
: clone $migration;
}

return is_object($migration) ? $migration : new $class;
return new $class;
}

/**
Expand Down

0 comments on commit 9534eaa

Please sign in to comment.