[CLEANUP] Adjust code to coding guidelines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / PropertyType.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
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 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * The property types supported by the JCR standard.
32 *
33 * The STRING property type is used to store strings.
34 * BINARY properties are used to store binary data.
35 * The LONG property type is used to store integers.
36 * The DECIMAL property type is used to store precise decimal numbers.
37 * The DOUBLE property type is used to store floating point numbers.
38 * The DATE property type is used to store time and date information. See 4.2.6.1 Date in the specification.
39 * The BOOLEAN property type is used to store boolean values.
40 * A NAME is a pairing of a namespace and a local name. When read, the namespace is mapped to the current prefix. See 4.2.6.2 Name in the specification.
41 * A PATH property is an ordered list of path elements. A path element is a NAME with an optional index. When read, the NAMEs within the path are mapped to their current prefix. A path may be absolute or relative. See 4.2.6.3 Path in the specification.
42 * A REFERENCE property stores the identifier of a referenceable node (one having type mix:referenceable), which must exist within the same workspace or session as the REFERENCE property. A REFERENCE property enforces this referential integrity by preventing (in level 2 implementations) the removal of its target node. See 4.2.6.4 Reference in the specification.
43 * A WEAKREFERENCE property stores the identifier of a referenceable node (one having type mix:referenceable). A WEAKREFERENCE property does not enforce referential integrity. See 4.2.6.5 Weak Reference in the specification.
44 * A URI property is identical to STRING property except that it only accepts values that conform to the syntax of a URI-reference as defined in RFC 3986. See also 4.2.6.6 URI in the specification.
45 * UNDEFINED can be used within a property definition (see 4.7.5 Property Definitions) to specify that the property in question may be of any type. However, it cannot be the actual type of any property instance. For example it will never be returned by Property.getType() and (in level 2 implementations) it cannot be assigned as the type when creating a new property.
46 */
47 class PropertyType {
48
49 /**
50 * This constant can be used within a property definition to specify that
51 * the property in question may be of any type.
52 * However, it cannot be the actual type of any property instance. For
53 * example, it will never be returned by Property#getType and it cannot be
54 * assigned as the type when creating a new property.
55 */
56 const UNDEFINED = 0;
57
58 /**
59 * The STRING property type is used to store strings.
60 */
61 const STRING = 1;
62
63 /**
64 * BINARY properties are used to store binary data.
65 */
66 const BINARY = 2;
67
68 /**
69 * The LONG property type is used to store integers.
70 */
71 const LONG = 3;
72
73 /**
74 * The DOUBLE property type is used to store floating point numbers.
75 */
76 const DOUBLE = 4;
77
78 /**
79 * The DATE property type is used to store time and date information.
80 */
81 const DATE = 5;
82
83 /**
84 * The BOOLEAN property type is used to store boolean values.
85 */
86 const BOOLEAN = 6;
87
88 /**
89 * A NAME is a pairing of a namespace and a local name. When read, the
90 * namespace is mapped to the current prefix.
91 *
92 * WE DO NOT USE THIS IN EXTBASE!
93 */
94 const NAME = 7;
95
96 /**
97 * A PATH property is an ordered list of path elements. A path element is a
98 * NAME with an optional index. When read, the NAMEs within the path are
99 * mapped to their current prefix. A path may be absolute or relative.
100 *
101 * WE DO NOT USE THIS IN EXTBASE!
102 */
103 const PATH = 8;
104
105 /**
106 * A REFERENCE property stores the identifier of a referenceable node (one
107 * having type mix:referenceable), which must exist within the same
108 * workspace or session as the REFERENCE property. A REFERENCE property
109 * enforces this referential integrity by preventing the removal of its
110 * target node.
111 */
112 const REFERENCE = 9;
113
114 /**
115 * A WEAKREFERENCE property stores the identifier of a referenceable node
116 * (one having type mix:referenceable). A WEAKREFERENCE property does not
117 * enforce referential integrity.
118 *
119 * WE DO NOT USE THIS IN EXTBASE!
120 */
121 const WEAKREFERENCE = 10;
122
123 /**
124 * A URI property is identical to STRING property except that it only
125 * accepts values that conform to the syntax of a URI-reference as defined
126 * in RFC 3986.
127 *
128 * WE DO NOT USE THIS IN EXTBASE!
129 */
130 const URI = 11;
131
132 /**
133 * The DECIMAL property type is used to store precise decimal numbers.
134 *
135 * WE DO NOT USE THIS IN EXTBASE!
136 */
137 const DECIMAL = 12;
138
139 /**
140 * The INTEGER property type is used to store precise decimal numbers.
141 *
142 * WE DO NOT USE THIS IN EXTBASE!
143 */
144 const INTEGER = 13;
145
146 /**
147 * String constant for type name as used in serialization.
148 */
149 const TYPENAME_UNDEFINED = 'undefined';
150
151 /**
152 * String constant for type name as used in serialization.
153 */
154 const TYPENAME_STRING = 'String';
155
156 /**
157 * String constant for type name as used in serialization.
158 */
159 const TYPENAME_BINARY = 'Binary';
160
161 /**
162 * String constant for type name as used in serialization.
163 */
164 const TYPENAME_LONG = 'Long';
165
166 /**
167 * String constant for type name as used in serialization.
168 */
169 const TYPENAME_DOUBLE = 'Double';
170
171 /**
172 * String constant for type name as used in serialization.
173 */
174 const TYPENAME_DATE = 'Date';
175
176 /**
177 * String constant for type name as used in serialization.
178 */
179 const TYPENAME_BOOLEAN = 'Boolean';
180
181 /**
182 * String constant for type name as used in serialization.
183 */
184 const TYPENAME_NAME = 'Name';
185
186 /**
187 * String constant for type name as used in serialization.
188 */
189 const TYPENAME_PATH = 'Path';
190
191 /**
192 * String constant for type name as used in serialization.
193 */
194 const TYPENAME_REFERENCE = 'Reference';
195
196 /**
197 * String constant for type name as used in serialization.
198 */
199 const TYPENAME_WEAKREFERENCE = 'WeakReference';
200
201 /**
202 * String constant for type name as used in serialization.
203 */
204 const TYPENAME_URI = 'URI';
205
206 /**
207 * String constant for type name as used in serialization.
208 */
209 const TYPENAME_DECIMAL = 'Decimal';
210
211 /**
212 * String constant for type name as used in serialization.
213 */
214 const TYPENAME_INTEGER = 'Integer';
215
216 /**
217 * Make instantiation impossible...
218 *
219 * @return void
220 */
221 private function __construct() {
222 }
223
224 /**
225 * Returns the name of the specified type, as used in serialization.
226 *
227 * @param integer $type type the property type
228 * @return string name of the specified type
229 */
230 static public function nameFromValue($type) {
231 switch (intval($type)) {
232 default:
233 case self::UNDEFINED:
234 return self::TYPENAME_UNDEFINED;
235 break;
236 case self::STRING:
237 return self::TYPENAME_STRING;
238 break;
239 case self::BINARY:
240 return self::TYPENAME_BINARY;
241 break;
242 case self::BOOLEAN:
243 return self::TYPENAME_BOOLEAN;
244 break;
245 case self::LONG:
246 return self::TYPENAME_LONG;
247 break;
248 case self::DOUBLE:
249 return self::TYPENAME_DOUBLE;
250 break;
251 case self::DECIMAL:
252 return self::TYPENAME_DECIMAL;
253 break;
254 case self::INTEGER:
255 return self::TYPENAME_INTEGER;
256 break;
257 case self::DATE:
258 return self::TYPENAME_DATE;
259 break;
260 case self::NAME:
261 return self::TYPENAME_NAME;
262 break;
263 case self::PATH:
264 return self::TYPENAME_PATH;
265 break;
266 case self::REFERENCE:
267 return self::TYPENAME_REFERENCE;
268 break;
269 case self::WEAKREFERENCE:
270 return self::TYPENAME_WEAKREFERENCE;
271 break;
272 case self::URI:
273 return self::TYPENAME_URI;
274 break;
275 }
276 }
277
278 /**
279 * Returns the numeric constant value of the type with the specified name.
280 *
281 * @param string $name The name of the property type
282 * @return int The numeric constant value
283 */
284 static public function valueFromName($name) {
285 switch ($name) {
286 default:
287 case self::TYPENAME_UNDEFINED:
288 return self::UNDEFINED;
289 break;
290 case self::TYPENAME_STRING:
291 return self::STRING;
292 break;
293 case self::TYPENAME_BINARY:
294 return self::BINARY;
295 break;
296 case self::TYPENAME_LONG:
297 return self::LONG;
298 break;
299 case self::TYPENAME_DOUBLE:
300 return self::DOUBLE;
301 break;
302 case self::TYPENAME_DECIMAL:
303 return self::DECIMAL;
304 break;
305 case self::TYPENAME_INTEGER:
306 return self::INTEGER;
307 break;
308 case self::TYPENAME_DATE:
309 return self::DATE;
310 break;
311 case self::TYPENAME_BOOLEAN:
312 return self::BOOLEAN;
313 break;
314 case self::TYPENAME_NAME:
315 return self::NAME;
316 break;
317 case self::TYPENAME_PATH:
318 return self::PATH;
319 break;
320 case self::TYPENAME_REFERENCE:
321 return self::REFERENCE;
322 break;
323 case self::TYPENAME_WEAKREFERENCE:
324 return self::WEAKREFERENCE;
325 break;
326 case self::TYPENAME_URI:
327 return self::URI;
328 break;
329 }
330 }
331
332 /**
333 * Returns the numeric constant value of the type for the given PHP type
334 * name as returned by gettype().
335 *
336 * @param string $type
337 * @return integer
338 */
339 static public function valueFromType($type) {
340 switch (strtolower($type)) {
341 case 'string':
342 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::STRING;
343 break;
344 case 'boolean':
345 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::BOOLEAN;
346 break;
347 case 'integer':
348 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::LONG;
349 break;
350 case 'float':
351
352 case 'double':
353 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::DOUBLE;
354 break;
355 case 'integer':
356
357 case 'int':
358 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::INTEGER;
359 break;
360 case 'datetime':
361 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::DATE;
362 break;
363 default:
364 return \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::UNDEFINED;
365 }
366 }
367 }
368
369 ?>