Revert "[CLEANUP] Rework/simplify copyright header and remove @package"
[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 * @inject
62 */
63 protected $objectManager;
64
65 /**
66 * Returns the list of source types the TypeConverter can handle.
67 * Must be PHP simple types, classes or object is not allowed.
68 *
69 * @return array<string>
70 * @api
71 */
72 public function getSupportedSourceTypes() {
73 return $this->sourceTypes;
74 }
75
76 /**
77 * Return the target type this TypeConverter converts to.
78 * Can be a simple type or a class name.
79 *
80 * @return string
81 * @api
82 */
83 public function getSupportedTargetType() {
84 return $this->targetType;
85 }
86
87 /**
88 * Returns the $originalTargetType unchanged in this implementation.
89 *
90 * @param mixed $source the source data
91 * @param string $originalTargetType the type we originally want to convert to
92 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
93 * @return string
94 * @api
95 */
96 public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
97 return $originalTargetType;
98 }
99
100 /**
101 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
102 *
103 * @return integer
104 * @api
105 */
106 public function getPriority() {
107 return $this->priority;
108 }
109
110 /**
111 * This implementation always returns TRUE for this method.
112 *
113 * @param mixed $source the source data
114 * @param string $targetType the type to convert to.
115 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
116 * @api
117 */
118 public function canConvertFrom($source, $targetType) {
119 return TRUE;
120 }
121
122 /**
123 * Returns an empty list of sub property names
124 *
125 * @param mixed $source
126 * @return array
127 * @api
128 */
129 public function getSourceChildPropertiesToBeConverted($source) {
130 return array();
131 }
132
133 /**
134 * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
135 *
136 * @param string $targetType
137 * @param string $propertyName
138 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
139 * @api
140 */
141 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
142 }
143 }