|
1
|
|
|
<?php |
|
2
|
|
|
namespace TildBJ\Seeder\Provider; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2016 Dennis Römmich <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
use TildBJ\Seeder\Traits; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* TableConfiguration |
|
31
|
|
|
* |
|
32
|
|
|
* @author Dennis Römmich<[email protected]> |
|
33
|
|
|
* @copyright Copyright belongs to the respective authors |
|
34
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later |
|
35
|
|
|
*/ |
|
36
|
|
|
class TableConfiguration |
|
37
|
|
|
{ |
|
38
|
|
|
use Traits\Language; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* extensionConfiguration |
|
42
|
|
|
* |
|
43
|
|
|
* @var array $tableConfiguration |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $tableConfiguration; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* table |
|
49
|
|
|
* |
|
50
|
|
|
* @var string $name |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $name; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* ExtensionConfigurationUtility constructor. |
|
56
|
|
|
* |
|
57
|
|
|
* @param $tableName |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct($tableName) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
if (!isset($GLOBALS['TCA'][$tableName])) { |
|
62
|
|
|
throw new \InvalidArgumentException( |
|
63
|
|
|
'Configuration for table ' . $tableName . ' not found!' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
$this->name = $tableName; |
|
67
|
|
|
$this->tableConfiguration = $GLOBALS['TCA'][$tableName]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* getName |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getName() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->name; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* getName |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getTitle() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->translate($this->tableConfiguration['ctrl']['title']); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* getColumns |
|
92
|
|
|
* |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getColumns() |
|
96
|
|
|
{ |
|
97
|
|
|
return array_keys($this->tableConfiguration['columns']); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* getColumnConfiguration |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $columnName |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getColumnConfiguration($columnName) |
|
107
|
|
|
{ |
|
108
|
|
|
if (!is_string($columnName)) { |
|
109
|
|
|
throw new \InvalidArgumentException( |
|
110
|
|
|
'Columns must be type of string. Type of ' . gettype($columnName) . ' given.' |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
if (!isset($this->tableConfiguration['columns'][$columnName])) { |
|
114
|
|
|
throw new \InvalidArgumentException( |
|
115
|
|
|
'Column ' . $columnName . ' does not exist for table ' . $this->name |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return array($columnName => $this->tableConfiguration['columns'][$columnName]['config']); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
public static function getAllTables() |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$tables = array(); |
|
128
|
|
|
foreach (array_keys($GLOBALS['TCA']) as $tableName) { |
|
129
|
|
|
$tables[$tableName] = $tableName; |
|
130
|
|
|
} |
|
131
|
|
|
return $tables; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: