1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\TDBM\Utils; |
5
|
|
|
|
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use TheCodingMachine\TDBM\ConfigurationInterface; |
9
|
|
|
use TheCodingMachine\TDBM\TDBMSchemaAnalyzer; |
10
|
|
|
|
11
|
|
|
class BeanRegistry |
12
|
|
|
{ |
13
|
|
|
/** @var BeanDescriptor[] table_name => BeanDescriptor */ |
14
|
|
|
private $registry = []; |
15
|
|
|
/** @var ConfigurationInterface */ |
16
|
|
|
private $configuration; |
17
|
|
|
/** @var Schema */ |
18
|
|
|
private $schema; |
19
|
|
|
/** @var TDBMSchemaAnalyzer */ |
20
|
|
|
private $tdbmSchemaAnalyzer; |
21
|
|
|
/** @var NamingStrategyInterface */ |
22
|
|
|
private $namingStrategy; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* BeanRegistry constructor. |
26
|
|
|
* @param ConfigurationInterface $configuration |
27
|
|
|
* @param Schema $schema |
28
|
|
|
* @param TDBMSchemaAnalyzer $tdbmSchemaAnalyzer |
29
|
|
|
* @param NamingStrategyInterface $namingStrategy |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
ConfigurationInterface $configuration, |
33
|
|
|
Schema $schema, |
34
|
|
|
TDBMSchemaAnalyzer $tdbmSchemaAnalyzer, |
35
|
|
|
NamingStrategyInterface $namingStrategy |
36
|
|
|
) { |
37
|
|
|
$this->configuration = $configuration; |
38
|
|
|
$this->schema = $schema; |
39
|
|
|
$this->tdbmSchemaAnalyzer = $tdbmSchemaAnalyzer; |
40
|
|
|
$this->namingStrategy = $namingStrategy; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function hasBeanForTable(Table $table): bool |
44
|
|
|
{ |
45
|
|
|
return isset($this->registry[$table->getName()]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function addBeanForTable(Table $table): BeanDescriptor |
49
|
|
|
{ |
50
|
|
|
if (!$this->hasBeanForTable($table)) { |
51
|
|
|
$this->registry[$table->getName()] = new BeanDescriptor( |
52
|
|
|
$table, |
53
|
|
|
$this->configuration->getBeanNamespace(), |
54
|
|
|
$this->configuration->getBeanNamespace() . '\\Generated', |
55
|
|
|
$this->configuration->getDaoNamespace(), |
56
|
|
|
$this->configuration->getDaoNamespace() . '\\Generated', |
57
|
|
|
$this->configuration->getSchemaAnalyzer(), |
58
|
|
|
$this->schema, |
59
|
|
|
$this->tdbmSchemaAnalyzer, |
60
|
|
|
$this->namingStrategy, |
61
|
|
|
$this->configuration->getAnnotationParser(), |
62
|
|
|
$this->configuration->getCodeGeneratorListener(), |
63
|
|
|
$this->configuration, |
64
|
|
|
$this |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
return $this->getBeanForTableName($table->getName()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getBeanForTableName(string $table): BeanDescriptor |
71
|
|
|
{ |
72
|
|
|
return $this->registry[$table]; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|