Skip to content

Commit 4b06bb4

Browse files
Resolve Blueprint out of the container (#40307)
Currently, it is almost impossible to swap the `Blueprint $table` implementation for migrations with a fake one from within a "package space". Because the `Schema` facade returns a new object each time from the `getFacadeAccessor` method (hence there is no way of mocking or hot swapping) and non of the other objects are resolved out of the container. (Connection objects or Builder objects) There is also no change of using the `resolver` property on the `Builder` class from a package space because if you set it before the migration starts it will be thrown away after the `Schema` is called in the migration. Currently "illuminate/database" depends on "illuminate/container" so we can use the Container class directly. This way it is possible to swap the Blueprint class upon the `registration phase`.
1 parent 62a73b2 commit 4b06bb4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Illuminate/Database/Schema/Builder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Database\Schema;
44

55
use Closure;
6+
use Illuminate\Container\Container;
67
use Illuminate\Database\Connection;
78
use InvalidArgumentException;
89
use LogicException;
@@ -380,7 +381,7 @@ protected function createBlueprint($table, Closure $callback = null)
380381
return call_user_func($this->resolver, $table, $callback, $prefix);
381382
}
382383

383-
return new Blueprint($table, $callback, $prefix);
384+
return Container::getInstance()->make(Blueprint::class, compact('table', 'callback', 'prefix'));
384385
}
385386

386387
/**

0 commit comments

Comments
 (0)