Skip to content

Commit 8059b39

Browse files
committed
Use string based accessor for Schema facade
1 parent 7bfc315 commit 8059b39

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

src/Illuminate/Database/DatabaseServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ protected function registerConnectionServices()
7272
return $app['db']->connection();
7373
});
7474

75+
$this->app->bind('db.schema', function ($app) {
76+
return $app['db']->connection()->getSchemaBuilder();
77+
});
78+
7579
$this->app->singleton('db.transactions', function ($app) {
7680
return new DatabaseTransactionsManager;
7781
});

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@ public function registerCoreContainerAliases()
13041304
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
13051305
'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
13061306
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
1307+
'db.schema' => [\Illuminate\Database\Schema\Builder::class],
13071308
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class],
13081309
'events' => [\Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
13091310
'files' => [\Illuminate\Filesystem\Filesystem::class],

src/Illuminate/Support/Facades/Facade.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ abstract class Facade
2323
*/
2424
protected static $resolvedInstance;
2525

26+
/**
27+
* Determine if the resolved facade should be cached.
28+
*
29+
* @var bool
30+
*/
31+
protected static $cached = true;
32+
2633
/**
2734
* Run a Closure when the facade has been resolved.
2835
*
@@ -84,8 +91,8 @@ public static function shouldReceive()
8491
$name = static::getFacadeAccessor();
8592

8693
$mock = static::isMock()
87-
? static::$resolvedInstance[$name]
88-
: static::createFreshMockInstance();
94+
? static::$resolvedInstance[$name]
95+
: static::createFreshMockInstance();
8996

9097
return $mock->shouldReceive(...func_get_args());
9198
}
@@ -197,21 +204,21 @@ protected static function getFacadeAccessor()
197204
/**
198205
* Resolve the facade root instance from the container.
199206
*
200-
* @param object|string $name
207+
* @param string $name
201208
* @return mixed
202209
*/
203210
protected static function resolveFacadeInstance($name)
204211
{
205-
if (is_object($name)) {
206-
return $name;
207-
}
208-
209212
if (isset(static::$resolvedInstance[$name])) {
210213
return static::$resolvedInstance[$name];
211214
}
212-
215+
dump(array_keys(static::$resolvedInstance));
213216
if (static::$app) {
214-
return static::$resolvedInstance[$name] = static::$app[$name];
217+
if (static::$cached) {
218+
return static::$resolvedInstance[$name] = static::$app[$name];
219+
}
220+
221+
return static::$app[$name];
215222
}
216223
}
217224

src/Illuminate/Support/Facades/RateLimiter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ class RateLimiter extends Facade
2424
*/
2525
protected static function getFacadeAccessor()
2626
{
27-
return 'Illuminate\Cache\RateLimiter';
27+
return \Illuminate\Cache\RateLimiter::class;
2828
}
2929
}

src/Illuminate/Support/Facades/Schema.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
*/
2525
class Schema extends Facade
2626
{
27+
/**
28+
* Determine if the resolved facade should be cached.
29+
*
30+
* @var bool
31+
*/
32+
protected static $cached = false;
33+
2734
/**
2835
* Get a schema builder instance for a connection.
2936
*
@@ -36,12 +43,12 @@ public static function connection($name)
3643
}
3744

3845
/**
39-
* Get a schema builder instance for the default connection.
46+
* Get the registered name of the component.
4047
*
41-
* @return \Illuminate\Database\Schema\Builder
48+
* @return string
4249
*/
4350
protected static function getFacadeAccessor()
4451
{
45-
return static::$app['db']->connection()->getSchemaBuilder();
52+
return 'db.schema';
4653
}
4754
}

tests/Database/DatabaseMigratorIntegrationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ protected function setUp(): void
4141

4242
$container = new Container;
4343
$container->instance('db', $db->getDatabaseManager());
44+
$container->bind('db.schema', function ($app) {
45+
return $app['db']->connection()->getSchemaBuilder();
46+
});
4447

4548
Facade::setFacadeApplication($container);
4649

0 commit comments

Comments
 (0)