|
2 | 2 |
|
3 | 3 | namespace Dyrynda\Database;
|
4 | 4 |
|
5 |
| -use Illuminate\Database\Connection; |
6 |
| -use Illuminate\Database\Schema\ColumnDefinition; |
7 |
| -use Illuminate\Database\Schema\Grammars\Grammar; |
8 | 5 | use Illuminate\Support\Fluent;
|
9 | 6 | use Illuminate\Support\ServiceProvider;
|
10 | 7 | use Illuminate\Database\Schema\Blueprint;
|
11 |
| -use Dyrynda\Database\Connection\MySqlConnection; |
12 |
| -use Dyrynda\Database\Connection\SQLiteConnection; |
13 |
| -use Dyrynda\Database\Connection\PostgresConnection; |
| 8 | +use Illuminate\Database\Schema\ColumnDefinition; |
| 9 | +use Illuminate\Database\Schema\Grammars\Grammar; |
14 | 10 | use Dyrynda\Database\Exceptions\UnknownGrammarClass;
|
15 | 11 |
|
16 | 12 | class LaravelEfficientUuidServiceProvider extends ServiceProvider
|
17 | 13 | {
|
18 |
| - /** |
19 |
| - * Bootstrap any application services. |
20 |
| - * |
21 |
| - * @return void |
22 |
| - */ |
23 |
| - public function boot() |
24 |
| - { |
25 |
| - // |
26 |
| - } |
27 |
| - |
28 |
| - /** |
29 |
| - * Register any application services. |
30 |
| - * |
31 |
| - * @return void |
32 |
| - */ |
33 | 14 | public function register()
|
34 | 15 | {
|
35 |
| - |
36 | 16 | Grammar::macro('typeEfficientUuid', function (Fluent $column) {
|
37 |
| - $className = (new \ReflectionClass($this))->getShortName(); |
| 17 | + switch (class_basename(static::class)) { |
| 18 | + case 'MySqlGrammar': |
| 19 | + return sprintf('binary(%d)', $column->length ?? 16); |
38 | 20 |
|
39 |
| - if ($className === "MySqlGrammar") { |
40 |
| - return sprintf('binary(%d)', $column->length ?? 16); |
41 |
| - } |
| 21 | + case 'PostgresGrammar': |
| 22 | + return 'bytea'; |
42 | 23 |
|
43 |
| - if ($className === "PostgresGrammar") { |
44 |
| - return 'bytea'; |
45 |
| - } |
| 24 | + case 'SQLiteGrammar': |
| 25 | + return 'blob(256)'; |
46 | 26 |
|
47 |
| - if ($className === "SQLiteGrammar") { |
48 |
| - return 'blob(256)'; |
| 27 | + default: |
| 28 | + throw new UnknownGrammarClass; |
49 | 29 | }
|
50 |
| - |
51 |
| - throw new UnknownGrammarClass(); |
52 | 30 | });
|
53 | 31 |
|
54 |
| - |
55 | 32 | Blueprint::macro('efficientUuid', function ($column): ColumnDefinition {
|
56 |
| - /** @var Blueprint $this */ |
| 33 | + /* @var Blueprint $this */ |
57 | 34 | return $this->addColumn('efficientUuid', $column);
|
58 | 35 | });
|
59 | 36 | }
|
|
0 commit comments