-
Notifications
You must be signed in to change notification settings - Fork 178
/
AbstractTable.php
47 lines (37 loc) · 1.16 KB
/
AbstractTable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace LaravelDoctrine\ORM;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
// phpcs:disable SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix
abstract class AbstractTable
{
public function __construct(protected string $table)
{
}
public function build(): Table
{
return new Table(
$this->table,
$this->columns(),
$this->indices(),
);
}
protected function column(string $name, string $type, bool $autoincrement = false): Column
{
$column = new Column($name, Type::getType($type));
$column->setAutoincrement($autoincrement);
return $column;
}
/** @param string[] $columns */
protected function index(string $name, array $columns, bool $unique = false, bool $primary = false): Index
{
return new Index($name, $columns, $unique, $primary);
}
/** @return Column[] */
abstract protected function columns(): array;
/** @return Index[] */
abstract protected function indices(): array;
}