[!!!][~API] Extbase (Persistence): $query->execute() now returns a plain array of...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / PropertyType.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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
28 /**
29 * The property types supported by the JCR standard.
30 *
31 * The STRING property type is used to store strings.
32 * BINARY properties are used to store binary data.
33 * The LONG property type is used to store integers.
34 * The DECIMAL property type is used to store precise decimal numbers.
35 * The DOUBLE property type is used to store floating point numbers.
36 * The DATE property type is used to store time and date information. See 4.2.6.1 Date in the specification.
37 * The BOOLEAN property type is used to store boolean values.
38 * 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.
39 * 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.
40 * 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.
41 * 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.
42 * 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.
43 * 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.
44 *
45 * @package Extbase
46 * @subpackage Persistence
47 * @version $Id$
48 */
49 final class Tx_Extbase_Persistence_PropertyType {
50
51 /**
52 * This constant can be used within a property definition to specify that
53 * the property in question may be of any type.
54 * However, it cannot be the actual type of any property instance. For
55 * example, it will never be returned by Property#getType and it cannot be
56 * assigned as the type when creating a new property.
57 */
58 const UNDEFINED = 0;
59
60 /**
61 * The STRING property type is used to store strings.
62 */
63 const STRING = 1;
64
65 /**
66 * BINARY properties are used to store binary data.
67 */
68 const BINARY = 2;
69
70 /**
71 * The LONG property type is used to store integers.
72 */
73 const LONG = 3;
74
75 /**
76 * The DOUBLE property type is used to store floating point numbers.
77 */
78 const DOUBLE = 4;
79
80 /**
81 * The DATE property type is used to store time and date information.
82 */
83 const DATE = 5;
84
85 /**
86 * The BOOLEAN property type is used to store boolean values.
87 */
88 const BOOLEAN = 6;
89
90 /**
91 * A NAME is a pairing of a namespace and a local name. When read, the
92 * namespace is mapped to the current prefix.
93 *
94 * WE DO NOT USE THIS IN EXTBASE!
95 */
96 const NAME = 7;
97
98 /**
99 * A PATH property is an ordered list of path elements. A path element is a
100 * NAME with an optional index. When read, the NAMEs within the path are
101 * mapped to their current prefix. A path may be absolute or relative.
102 *
103 * WE DO NOT USE THIS IN EXTBASE!
104 */
105 const PATH = 8;
106
107 /**
108 * A REFERENCE property stores the identifier of a referenceable node (one
109 * having type mix:referenceable), which must exist within the same
110 * workspace or session as the REFERENCE property. A REFERENCE property
111 * enforces this referential integrity by preventing the removal of its
112 * target node.
113 */
114 const REFERENCE = 9;
115
116 /**
117 * A WEAKREFERENCE property stores the identifier of a referenceable node
118 * (one having type mix:referenceable). A WEAKREFERENCE property does not
119 * enforce referential integrity.
120 *
121 * WE DO NOT USE THIS IN EXTBASE!
122 */
123 const WEAKREFERENCE = 10;
124
125 /**
126 * A URI property is identical to STRING property except that it only
127 * accepts values that conform to the syntax of a URI-reference as defined
128 * in RFC 3986.
129 *
130 * WE DO NOT USE THIS IN EXTBASE!
131 */
132 const URI = 11;
133
134 /**
135 * The DECIMAL property type is used to store precise decimal numbers.
136 *
137 * WE DO NOT USE THIS IN EXTBASE!
138 */
139 const DECIMAL = 12;
140
141 /**
142 * The INTEGER property type is used to store precise decimal numbers.
143 *
144 * WE DO NOT USE THIS IN EXTBASE!
145 */
146 const INTEGER = 13;
147
148 /**
149 * String constant for type name as used in serialization.
150 */
151 const TYPENAME_UNDEFINED = 'undefined';
152
153 /**
154 * String constant for type name as used in serialization.
155 */
156 const TYPENAME_STRING = 'String';
157
158 /**
159 * String constant for type name as used in serialization.
160 */
161 const TYPENAME_BINARY = 'Binary';
162
163 /**
164 * String constant for type name as used in serialization.
165 */
166 const TYPENAME_LONG = 'Long';
167
168 /**
169 * String constant for type name as used in serialization.
170 */
171 const TYPENAME_DOUBLE = 'Double';
172
173 /**
174 * String constant for type name as used in serialization.
175 */
176 const TYPENAME_DATE = 'Date';
177
178 /**
179 * String constant for type name as used in serialization.
180 */
181 const TYPENAME_BOOLEAN = 'Boolean';
182
183 /**
184 * String constant for type name as used in serialization.
185 */
186 const TYPENAME_NAME = 'Name';
187
188 /**
189 * String constant for type name as used in serialization.
190 */
191 const TYPENAME_PATH = 'Path';
192
193 /**
194 * String constant for type name as used in serialization.
195 */
196 const TYPENAME_REFERENCE = 'Reference';
197
198 /**
199 * String constant for type name as used in serialization.
200 */
201 const TYPENAME_WEAKREFERENCE = 'WeakReference';
202
203 /**
204 * String constant for type name as used in serialization.
205 */
206 const TYPENAME_URI= 'URI';
207
208 /**
209 * String constant for type name as used in serialization.
210 */
211 const TYPENAME_DECIMAL = 'Decimal';
212
213 /**
214 * String constant for type name as used in serialization.
215 */
216 const TYPENAME_INTEGER = 'Integer';
217
218 /**
219 * Make instantiation impossible...
220 *
221 * @return void
222 */
223 private function __construct() {}
224
225 /**
226 * Returns the name of the specified type, as used in serialization.
227 *
228 * @param integer $type type the property type
229 * @return string name of the specified type
230 */
231 static public function nameFromValue($type) {
232 switch (intval($type)) {
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 /**
280 * Returns the numeric constant value of the type with the specified name.
281 *
282 * @param string $name The name of the property type
283 * @return int The numeric constant value
284 */
285 static public function valueFromName($name) {
286 switch ($name) {
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 Tx_Extbase_Persistence_PropertyType::STRING;
343 break;
344 case 'boolean':
345 return Tx_Extbase_Persistence_PropertyType::BOOLEAN;
346 break;
347 case 'integer':
348 return Tx_Extbase_Persistence_PropertyType::LONG;
349 break;
350 case 'float':
351 case 'double':
352 return Tx_Extbase_Persistence_PropertyType::DOUBLE;
353 break;
354 case 'integer':
355 case 'int':
356 return Tx_Extbase_Persistence_PropertyType::INTEGER;
357 break;
358 case 'datetime':
359 return Tx_Extbase_Persistence_PropertyType::DATE;
360 break;
361 default:
362 return Tx_Extbase_Persistence_PropertyType::UNDEFINED;
363 }
364 }
365 }
366
367 ?>