From 531ed57073811c25d19141fcbb166dd7af5b798b Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 30 Apr 2022 11:42:47 +1200 Subject: [PATCH] fix: provide laravel 9-supported facade accessor for custom schema builder --- src/app/Providers/BluewingServiceProvider.php | 3 +- src/app/Schema/Schema.php | 28 +++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/app/Providers/BluewingServiceProvider.php b/src/app/Providers/BluewingServiceProvider.php index 640f02e..1d022e4 100644 --- a/src/app/Providers/BluewingServiceProvider.php +++ b/src/app/Providers/BluewingServiceProvider.php @@ -3,6 +3,7 @@ namespace Bluewing\Providers; use Bluewing\Database\PostgresConnection as BluewingPostgresConnection; +use Bluewing\Schema\Schema; use Illuminate\Database\Connection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\ServiceProvider; @@ -14,7 +15,7 @@ class BluewingServiceProvider extends ServiceProvider { */ public function register() { - + $this->app->bind('db.schema', fn() => Schema::customizedSchemaBuilder()); } /** diff --git a/src/app/Schema/Schema.php b/src/app/Schema/Schema.php index 6946214..f26e19a 100644 --- a/src/app/Schema/Schema.php +++ b/src/app/Schema/Schema.php @@ -8,46 +8,38 @@ use Bluewing\Schema\Blueprint as BluewingBlueprint; /** - * Class Schema - * * @package Bluewing\Schema * - * Subclass of `Schema` that returns the appropriate instance of `Blueprint` containing - * additional utility functions. + * Subclass of `Schema` that returns the appropriate instance of `Blueprint` containing additional utility functions. * * @see https://stackoverflow.com/questions/22444685/extend-blueprint-class/57539154#57539154 */ class Schema extends BaseSchema { - /** * Get a schema builder instance for a connection. * - * @param string|null $name + * @param string|null $name + * * @return Builder */ public static function connection($name): Builder { - /** @var Builder $builder */ - $builder = static::$app['db']->connection($name)->getSchemaBuilder(); - $builder->blueprintResolver(static function($table, $callback) { - return new BluewingBlueprint($table, $callback); - }); - return $builder; + return static::customizedSchemaBuilder($name); } /** - * Get a schema builder instance for the default connection. + * Retrieves an instance of the schema `Builder` with a customized `Blueprint` class. + * + * @param string|null $name * * @return Builder */ - protected static function getFacadeAccessor(): Builder + public static function customizedSchemaBuilder(string|null $name = null): Builder { /** @var Builder $builder */ - $builder = static::$app['db']->connection()->getSchemaBuilder(); - $builder->blueprintResolver(static function($table, $callback) { - return new BluewingBlueprint($table, $callback); - }); + $builder = static::$app['db']->connection($name)->getSchemaBuilder(); + $builder->blueprintResolver(static fn($table, $callback) => new BluewingBlueprint($table, $callback)); return $builder; } }