94b196c3a151c0b96ca1e77320f3406b1f36277a
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / AbstractTypeConverter.php
1 <?php
2
3 /* *
4 * This script belongs to the Extbase framework *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * Type converter which provides sensible default implementations for most methods. If you extend this class
25 * you only need to do the following:
26 * - set $sourceTypes
27 * - set $targetType
28 * - set $priority
29 * - implement convertFrom()
30 *
31 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
32 * @api
33 */
34 abstract class Tx_Extbase_Property_TypeConverter_AbstractTypeConverter implements Tx_Extbase_Property_TypeConverterInterface, t3lib_Singleton {
35
36 /**
37 * The source types this converter can convert.
38 *
39 * @var array<string>
40 * @api
41 */
42 protected $sourceTypes = array();
43
44 /**
45 * The target type this converter can convert to.
46 *
47 * @var string
48 * @api
49 */
50 protected $targetType = '';
51
52 /**
53 * The priority for this converter.
54 *
55 * @var integer
56 * @api
57 */
58 protected $priority;
59
60 /**
61 * Returns the list of source types the TypeConverter can handle.
62 * Must be PHP simple types, classes or object is not allowed.
63 *
64 * @return array<string>
65 * @api
66 */
67 public function getSupportedSourceTypes() {
68 return $this->sourceTypes;
69 }
70
71 /**
72 * Return the target type this TypeConverter converts to.
73 * Can be a simple type or a class name.
74 *
75 * @return string
76 * @api
77 */
78 public function getSupportedTargetType() {
79 return $this->targetType;
80 }
81
82 /**
83 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
84 *
85 * @return integer
86 * @api
87 */
88 public function getPriority() {
89 return $this->priority;
90 }
91
92 /**
93 * This implementation always returns TRUE for this method.
94 *
95 * @param mixed $source the source data
96 * @param string $targetType the type to convert to.
97 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
98 * @api
99 */
100 public function canConvertFrom($source, $targetType) {
101 return TRUE;
102 }
103
104 /**
105 * Returns an empty list of sub property names
106 *
107 * @param mixed $source (unused)
108 * @return array<string>
109 * @api
110 */
111 public function getSourceChildPropertiesToBeConverted($source) {
112 return array();
113 }
114
115 /**
116 * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
117 *
118 * @param string $targetType
119 * @param string $propertyName
120 * @param Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration
121 * @return string
122 * @api
123 */
124 public function getTypeOfChildProperty($targetType, $propertyName, Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration) {
125 }
126 }
127 ?>