|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheCodingMachine\FluidSchema; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
8
|
|
|
|
|
9
|
|
|
class TdbmFluidSchema |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var FluidSchema |
|
13
|
|
|
*/ |
|
14
|
|
|
private $fluidSchema; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var NamingStrategyInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $namingStrategy; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var TdbmFluidTable[] |
|
23
|
|
|
*/ |
|
24
|
|
|
private $tdbmFluidTables; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param Schema $schema |
|
28
|
|
|
* @param null|NamingStrategyInterface $namingStrategy |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(Schema $schema, ?NamingStrategyInterface $namingStrategy = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->namingStrategy = $namingStrategy ?: new DefaultNamingStrategy(); |
|
33
|
|
|
$this->fluidSchema = new FluidSchema($schema, $this->namingStrategy); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function table(string $name): TdbmFluidTable |
|
37
|
|
|
{ |
|
38
|
|
|
$name = $this->namingStrategy->quoteIdentifier($name); |
|
39
|
|
|
|
|
40
|
|
|
if (isset($this->tdbmFluidTables[$name])) { |
|
41
|
|
|
return $this->tdbmFluidTables[$name]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->tdbmFluidTables[$name] = new TdbmFluidTable($this, $this->fluidSchema->table($name), $this->namingStrategy); |
|
45
|
|
|
|
|
46
|
|
|
return $this->tdbmFluidTables[$name]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Creates a table joining 2 other tables through a foreign key. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $table1 |
|
53
|
|
|
* @param string $table2 |
|
54
|
|
|
* @return TdbmFluidJunctionTableOptions |
|
55
|
|
|
*/ |
|
56
|
|
|
public function junctionTable(string $table1, string $table2): TdbmFluidJunctionTableOptions |
|
57
|
|
|
{ |
|
58
|
|
|
$this->fluidSchema->junctionTable($table1, $table2); |
|
59
|
|
|
$tableName = $this->namingStrategy->getJointureTableName($table1, $table2); |
|
60
|
|
|
|
|
61
|
|
|
return new TdbmFluidJunctionTableOptions($this->table($tableName)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the underlying schema. |
|
66
|
|
|
* @return Schema |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getDbalSchema(): Schema |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->fluidSchema->getDbalSchema(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|