[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 file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Type converter which provides sensible default implementations for most methods. If you extend this class
19 * you only need to do the following:
20 * - set $sourceTypes
21 * - set $targetType
22 * - set $priority
23 * - implement convertFrom()
24 *
25 * @api
26 */
27 abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\TypeConverterInterface, \TYPO3\CMS\Core\SingletonInterface {
28
29 /**
30 * The source types this converter can convert.
31 *
32 * @var array<string>
33 * @api
34 */
35 protected $sourceTypes = array();
36
37 /**
38 * The target type this converter can convert to.
39 *
40 * @var string
41 * @api
42 */
43 protected $targetType = '';
44
45 /**
46 * The priority for this converter.
47 *
48 * @var integer
49 * @api
50 */
51 protected $priority;
52
53 /**
54 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
55 * @inject
56 */
57 protected $objectManager;
58
59 /**
60 * Returns the list of source types the TypeConverter can handle.
61 * Must be PHP simple types, classes or object is not allowed.
62 *
63 * @return array<string>
64 * @api
65 */
66 public function getSupportedSourceTypes() {
67 return $this->sourceTypes;
68 }
69
70 /**
71 * Return the target type this TypeConverter converts to.
72 * Can be a simple type or a class name.
73 *
74 * @return string
75 * @api
76 */
77 public function getSupportedTargetType() {
78 return $this->targetType;
79 }
80
81 /**
82 * Returns the $originalTargetType unchanged in this implementation.
83 *
84 * @param mixed $source the source data
85 * @param string $originalTargetType the type we originally want to convert to
86 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
87 * @return string
88 * @api
89 */
90 public function getTargetTypeForSource($source, $originalTargetType, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
91 return $originalTargetType;
92 }
93
94 /**
95 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
96 *
97 * @return integer
98 * @api
99 */
100 public function getPriority() {
101 return $this->priority;
102 }
103
104 /**
105 * This implementation always returns TRUE for this method.
106 *
107 * @param mixed $source the source data
108 * @param string $targetType the type to convert to.
109 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
110 * @api
111 */
112 public function canConvertFrom($source, $targetType) {
113 return TRUE;
114 }
115
116 /**
117 * Returns an empty list of sub property names
118 *
119 * @param mixed $source
120 * @return array
121 * @api
122 */
123 public function getSourceChildPropertiesToBeConverted($source) {
124 return array();
125 }
126
127 /**
128 * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
129 *
130 * @param string $targetType
131 * @param string $propertyName
132 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
133 * @api
134 */
135 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
136 }
137 }