[TASK] Backport Flow property mapper
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / AbstractTypeConverter.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
3
4 /* *
5 * This script belongs to the Extbase framework *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
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 * @api
32 */
33 abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\TypeConverterInterface, \TYPO3\CMS\Core\SingletonInterface {
34
35 /**
36 * The source types this converter can convert.
37 *
38 * @var array<string>
39 * @api
40 */
41 protected $sourceTypes = array();
42
43 /**
44 * The target type this converter can convert to.
45 *
46 * @var string
47 * @api
48 */
49 protected $targetType = '';
50
51 /**
52 * The priority for this converter.
53 *
54 * @var integer
55 * @api
56 */
57 protected $priority;
58
59 /**
60 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
61 */
62 protected $objectManager;
63
64 /**
65 * Injects the object manager.
66 *
67 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
68 */
69 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
70 $this->objectManager = $objectManager;
71 }
72
73 /**
74 * Returns the list of source types the TypeConverter can handle.
75 * Must be PHP simple types, classes or object is not allowed.
76 *
77 * @return array<string>
78 * @api
79 */
80 public function getSupportedSourceTypes() {
81 return $this->sourceTypes;
82 }
83
84 /**
85 * Return the target type this TypeConverter converts to.
86 * Can be a simple type or a class name.
87 *
88 * @return string
89 * @api
90 */
91 public function getSupportedTargetType() {
92 return $this->targetType;
93 }
94
95 /**
96 * Returns the $originalTargetType unchanged in this implementation.
97 *
98 * @param mixed $source the source data
99 * @param string $originalTargetType the type we originally want to convert to
100 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
101 * @return string
102 * @api
103 */
104 public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
105 return $originalTargetType;
106 }
107
108 /**
109 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
110 *
111 * @return integer
112 * @api
113 */
114 public function getPriority() {
115 return $this->priority;
116 }
117
118 /**
119 * This implementation always returns TRUE for this method.
120 *
121 * @param mixed $source the source data
122 * @param string $targetType the type to convert to.
123 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
124 * @api
125 */
126 public function canConvertFrom($source, $targetType) {
127 return TRUE;
128 }
129
130 /**
131 * Returns an empty list of sub property names
132 *
133 * @param mixed $source
134 * @return array<string>
135 * @api
136 */
137 public function getSourceChildPropertiesToBeConverted($source) {
138 return array();
139 }
140
141 /**
142 * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
143 *
144 * @param string $targetType
145 * @param string $propertyName
146 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
147 * @return string
148 * @api
149 */
150 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
151 }
152 }
153 ?>