TYPO3 CMS  TYPO3_7-6
AbstractSpecifics.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 abstract class AbstractSpecifics
22 {
26  const TABLE_MAXLENGTH = 'table_maxlength';
27  const FIELD_MAXLENGTH = 'field_maxlength';
28  const LIST_MAXEXPRESSIONS = 'list_maxexpressions';
29  const PARTIAL_STRING_INDEX = 'partial_string_index';
30  const CAST_FIND_IN_SET = 'cast_find_in_set';
31 
38  protected $specificProperties = [];
39 
46  'STRING' => 'C',
47  'CHAR' => 'C',
48  'VARCHAR' => 'C',
49  'TINYBLOB' => 'C',
50  'TINYTEXT' => 'C',
51  'ENUM' => 'C',
52  'SET' => 'C',
53  'TEXT' => 'XL',
54  'LONGTEXT' => 'XL',
55  'MEDIUMTEXT' => 'XL',
56  'IMAGE' => 'B',
57  'LONGBLOB' => 'B',
58  'BLOB' => 'B',
59  'MEDIUMBLOB' => 'B',
60  'YEAR' => 'D',
61  'DATE' => 'D',
62  'TIME' => 'T',
63  'DATETIME' => 'T',
64  'TIMESTAMP' => 'T',
65  'FLOAT' => 'F',
66  'DOUBLE' => 'F',
67  'INT' => 'I8',
68  'INTEGER' => 'I8',
69  'TINYINT' => 'I8',
70  'SMALLINT' => 'I8',
71  'MEDIUMINT' => 'I8',
72  'BIGINT' => 'I8',
73  ];
74 
79 
86  'C' => 'VARCHAR',
87  'C2' => 'VARCHAR',
88  'X' => 'LONGTEXT',
89  'XL' => 'LONGTEXT',
90  'X2' => 'LONGTEXT',
91  'B' => 'LONGBLOB',
92  'D' => 'DATE',
93  'T' => 'DATETIME',
94  'L' => 'TINYINT',
95  'I' => 'BIGINT',
96  'I1' => 'BIGINT',
97  'I2' => 'BIGINT',
98  'I4' => 'BIGINT',
99  'I8' => 'BIGINT',
100  'F' => 'DOUBLE',
101  'N' => 'NUMERIC'
102  ];
103 
110 
114  public function __construct()
115  {
116  $this->nativeToMetaFieldTypeMap = array_merge($this->nativeToMetaFieldTypeMap, $this->nativeToMetaFieldTypeOverrides);
117  $this->metaToNativeFieldTypeMap = array_merge($this->metaToNativeFieldTypeMap, $this->metaToNativeFieldTypeOverrides);
118  }
119 
126  public function specificExists($specific)
127  {
128  return isset($this->specificProperties[$specific]);
129  }
130 
137  public function getSpecific($specific)
138  {
139  return $this->specificProperties[$specific];
140  }
141 
149  public function splitMaxExpressions($expressionList, $preserveArrayKeys = false)
150  {
151  if (!$this->specificExists(self::LIST_MAXEXPRESSIONS)) {
152  return [$expressionList];
153  }
154 
155  return array_chunk($expressionList, $this->getSpecific(self::LIST_MAXEXPRESSIONS), $preserveArrayKeys);
156  }
157 
166  public function truncateIdentifier($identifier, $specific)
167  {
168  if (!$this->specificExists($specific)) {
169  return $identifier;
170  }
171 
172  $maxLength = $this->getSpecific($specific);
173  if (strlen($identifier) > $maxLength) {
174  $truncateChars = 10;
175  $identifier = substr($identifier, 0, $maxLength - $truncateChars) . '_' . substr(sha1($identifier), 0, $truncateChars - 1);
176  }
177 
178  return $identifier;
179  }
180 
192  public function transformQueryParts(&$select_fields, &$from_table, &$where_clause, &$groupBy = '', &$orderBy = '', &$limit = '')
193  {
194  }
195 
204  public function transformFieldRowToMySQL($fieldRow, $metaType)
205  {
206  $mysqlType = $this->getNativeFieldType($metaType);
207  $mysqlType .= $this->getNativeFieldLength($mysqlType, $fieldRow['max_length']);
208 
209  $fieldRow['Field'] = $fieldRow['name'];
210  $fieldRow['Type'] = strtolower($mysqlType);
211  $fieldRow['Null'] = $this->getNativeNotNull($fieldRow['not_null']);
212  $fieldRow['Key'] = $this->getNativeKeyForField($fieldRow);
213  $fieldRow['Default'] = $this->getNativeDefaultValue($fieldRow);
214  $fieldRow['Extra'] = $this->getNativeExtraFieldAttributes($fieldRow);
215 
216  return $fieldRow;
217  }
218 
225  public function getNativeFieldType($metaType)
226  {
227  $metaType = strtoupper($metaType);
228  return empty($this->metaToNativeFieldTypeMap[$metaType]) ? $metaType : $this->metaToNativeFieldTypeMap[$metaType];
229  }
230 
237  public function getMetaFieldType($nativeType)
238  {
239  $nativeType = strtoupper($nativeType);
240  return empty($this->nativeToMetaFieldTypeMap[$nativeType]) ? 'N' : $this->nativeToMetaFieldTypeMap[$nativeType];
241  }
242 
250  public function getNativeFieldLength($mysqlType, $maxLength)
251  {
252  if ($maxLength === -1) {
253  return '';
254  }
255  switch ($mysqlType) {
256  case 'INT':
257  return '(11)';
258  default:
259  return '(' . $maxLength . ')';
260  }
261  }
262 
269  protected function getNativeNotNull($notNull)
270  {
271  return (bool)$notNull ? 'NO' : 'YES';
272  }
273 
280  protected function getNativeDefaultValue($fieldDefinition)
281  {
282  return $fieldDefinition['default_value'];
283  }
284 
296  protected function getNativeKeyForField($fieldRow)
297  {
298  return '';
299  }
300 
309  protected function getNativeExtraFieldAttributes($fieldRow)
310  {
311  return '';
312  }
313 }
splitMaxExpressions($expressionList, $preserveArrayKeys=false)
transformQueryParts(&$select_fields, &$from_table, &$where_clause, &$groupBy='', &$orderBy='', &$limit='')