annotate src/Database/MySchema.php @ 2:b44434aaa767

Moving around the components. Made a big step in the right direction with the Builder and named joins being accessible.
author luka
date Wed, 18 Jun 2025 22:28:47 -0400
parents
children 84c75d9d90be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
1 <?php
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
2
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
3 namespace Libraries;
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
4
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
5 use Illuminate\Database\Schema\Builder;
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
6 use Illuminate\Support\Facades\Schema as BaseSchema;
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
7
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
8 class MySchema extends BaseSchema
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
9 {
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
10 /**
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
11 * Get a schema builder instance for a connection.
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
12 *
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
13 * @param string|null $name
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
14 */
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
15 public static function connection($name): Builder
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
16 {
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
17 return self::customizedSchemaBuilder($name);
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
18 }
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
19
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
20 /**
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
21 * Retrieves an instance of the schema `Builder` with a customized `Blueprint` class.
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
22 */
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
23 public static function customizedSchemaBuilder(?string $name = null): Builder
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
24 {
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
25 /** @var Builder $builder */
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
26 $builder = static::$app['db']->connection($name)->getSchemaBuilder();
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
27
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
28 $builder->blueprintResolver(static fn ($table, $callback, $prefix) => new MyBlueprint($table, $callback, $prefix));
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
29
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
30 return $builder;
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
31 }
b44434aaa767 Moving around the components.
luka
parents:
diff changeset
32 }