1 | <?php |
||
2 | |||
3 | |||
4 | namespace TheCodingMachine\TDBM\Schema; |
||
5 | |||
6 | |||
7 | use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
||
8 | |||
9 | class ForeignKey |
||
10 | { |
||
11 | public const FOREIGN_TABLE = 'foreignTable'; |
||
12 | public const LOCAL_COLUMNS = 'localColumns'; |
||
13 | public const FOREIGN_COLUMNS = 'foreignColumns'; |
||
14 | |||
15 | /** |
||
16 | * @var array<string, string|array<string>> |
||
17 | */ |
||
18 | private $foreignKey; |
||
19 | |||
20 | /** |
||
21 | * @param array<string, string|array<string>> $foreignKey |
||
22 | */ |
||
23 | public function __construct(array $foreignKey) |
||
24 | { |
||
25 | $this->foreignKey = $foreignKey; |
||
26 | } |
||
27 | |||
28 | public static function createFromFk(ForeignKeyConstraint $fk): self |
||
29 | { |
||
30 | return new self([ |
||
31 | self::FOREIGN_TABLE => $fk->getForeignTableName(), |
||
32 | self::LOCAL_COLUMNS => $fk->getUnquotedLocalColumns(), |
||
33 | self::FOREIGN_COLUMNS => $fk->getUnquotedForeignColumns(), |
||
34 | ]); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return array<string> |
||
39 | */ |
||
40 | public function getUnquotedLocalColumns(): array |
||
41 | { |
||
42 | return $this->foreignKey[self::LOCAL_COLUMNS]; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return array<string> |
||
47 | */ |
||
48 | public function getUnquotedForeignColumns(): array |
||
49 | { |
||
50 | return $this->foreignKey[self::FOREIGN_COLUMNS]; |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | |||
53 | public function getForeignTableName(): string |
||
54 | { |
||
55 | return $this->foreignKey[self::FOREIGN_TABLE]; |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | |||
58 | public function getCacheKey(): string |
||
59 | { |
||
60 | return 'from__'.implode(',', $this->getUnquotedLocalColumns()) . '__to__table__' . $this->getForeignTableName() . '__columns__' . implode(',', $this->getUnquotedForeignColumns()); |
||
61 | } |
||
62 | } |
||
63 |