1 | <?php |
||
23 | class TableFactory implements TableFactoryInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var TableRegistry $registry |
||
27 | */ |
||
28 | private $registry; |
||
29 | |||
30 | /** |
||
31 | * @var TableRecognizer $tableRecognizer |
||
32 | */ |
||
33 | private $tableRecognizer; |
||
34 | |||
35 | /** |
||
36 | * @param TableRegistry $registry |
||
37 | */ |
||
38 | 3 | public function __construct(TableRegistry $registry) |
|
39 | { |
||
40 | 3 | $this->registry = $registry; |
|
41 | 3 | $this->tableRecognizer = new TableRecognizer(); |
|
42 | 3 | } |
|
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | 3 | public function createNewTable($table, BuilderInterface $qb) |
|
48 | { |
||
49 | 3 | $tableType = $this->tableRecognizer->recognizeType($table); |
|
50 | |||
51 | 3 | $tableClass = null; |
|
52 | |||
53 | switch ($tableType) { |
||
54 | 3 | case TableRecognizer::TYPE_CLOSURE: |
|
55 | 1 | $tableClass = $this->tableRecognizer->extractClassName($table); |
|
56 | 1 | break; |
|
57 | 3 | case TableRecognizer::TYPE_CLASS_NAME: |
|
58 | 1 | $tableClass = $table; |
|
59 | 1 | break; |
|
60 | 3 | case TableRecognizer::TYPE_TABLE_NAME: |
|
61 | 2 | $tableClass = $this->registry->getTableClass($table); |
|
62 | 2 | break; |
|
63 | 1 | case TableRecognizer::TYPE_SUB_QUERY: |
|
64 | 1 | return $this->createSubQueryTable($table, $qb); |
|
65 | } |
||
66 | |||
67 | 2 | return $this->doCreate($table, $tableClass, $qb); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param string $requestedTable |
||
72 | * @param string $tableClass |
||
73 | * @param BuilderInterface $qb |
||
74 | * |
||
75 | * @return mixed |
||
76 | */ |
||
77 | 2 | private function doCreate($requestedTable, $tableClass, BuilderInterface $qb) |
|
87 | |||
88 | /** |
||
89 | * @param BuilderInterface $subQb |
||
90 | * @param BuilderInterface $qb |
||
91 | * |
||
92 | * @return SubQueryTable |
||
93 | */ |
||
94 | 1 | private function createSubQueryTable(BuilderInterface $subQb, BuilderInterface $qb) |
|
98 | } |