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
|
17 |
|
public function __construct($tableName) |
60
|
|
|
{ |
61
|
17 |
View Code Duplication |
if (!isset($GLOBALS['TCA'][$tableName])) { |
|
|
|
|
62
|
1 |
|
throw new \InvalidArgumentException( |
63
|
1 |
|
'Configuration for table ' . $tableName . ' not found!' |
64
|
|
|
); |
65
|
|
|
} |
66
|
17 |
|
$this->name = $tableName; |
67
|
17 |
|
$this->tableConfiguration = $GLOBALS['TCA'][$tableName]; |
68
|
17 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* getName |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
1 |
|
public function getName() |
76
|
|
|
{ |
77
|
1 |
|
return $this->name; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* getName |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
1 |
|
public function getTitle() |
86
|
|
|
{ |
87
|
1 |
|
return $this->translate($this->tableConfiguration['ctrl']['title']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* getColumns |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
8 |
|
public function getColumns() |
96
|
|
|
{ |
97
|
8 |
|
return array_keys($this->tableConfiguration['columns']); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* getColumnConfiguration |
102
|
|
|
* |
103
|
|
|
* @param string $columnName |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
3 |
|
public function getColumnConfiguration($columnName) |
107
|
|
|
{ |
108
|
3 |
|
if (!is_string($columnName)) { |
109
|
1 |
|
throw new \InvalidArgumentException( |
110
|
1 |
|
'Columns must be type of string. Type of ' . gettype($columnName) . ' given.' |
111
|
|
|
); |
112
|
|
|
} |
113
|
2 |
|
if (!isset($this->tableConfiguration['columns'][$columnName])) { |
114
|
1 |
|
throw new \InvalidArgumentException( |
115
|
1 |
|
'Column ' . $columnName . ' does not exist for table ' . $this->name |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
return array($columnName => $this->tableConfiguration['columns'][$columnName]['config']); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
1 |
|
public static function getAllTables() |
126
|
|
|
{ |
127
|
1 |
|
$tables = array(); |
128
|
1 |
|
foreach (array_keys($GLOBALS['TCA']) as $tableName) { |
129
|
1 |
|
$tables[$tableName] = $tableName; |
130
|
|
|
} |
131
|
1 |
|
return $tables; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.