585fd42f952e8b744ca7b07bf64bbd168a73c591
[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 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
32 * @api
33 */
34 abstract class AbstractTypeConverter implements \TYPO3\CMS\Extbase\Property\TypeConverterInterface, \TYPO3\CMS\Core\SingletonInterface {
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 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
62 */
63 protected $objectManager;
64
65 /**
66 * Injects the object manager.
67 *
68 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
69 */
70 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
71 $this->objectManager = $objectManager;
72 }
73
74 /**
75 * Returns the list of source types the TypeConverter can handle.
76 * Must be PHP simple types, classes or object is not allowed.
77 *
78 * @return array<string>
79 * @api
80 */
81 public function getSupportedSourceTypes() {
82 return $this->sourceTypes;
83 }
84
85 /**
86 * Return the target type this TypeConverter converts to.
87 * Can be a simple type or a class name.
88 *
89 * @return string
90 * @api
91 */
92 public function getSupportedTargetType() {
93 return $this->targetType;
94 }
95
96 /**
97 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
98 *
99 * @return integer
100 * @api
101 */
102 public function getPriority() {
103 return $this->priority;
104 }
105
106 /**
107 * This implementation always returns TRUE for this method.
108 *
109 * @param mixed $source the source data
110 * @param string $targetType the type to convert to.
111 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
112 * @api
113 */
114 public function canConvertFrom($source, $targetType) {
115 return TRUE;
116 }
117
118 /**
119 * Returns an empty list of sub property names
120 *
121 * @param mixed $source (unused)
122 * @return array<string>
123 * @api
124 */
125 public function getSourceChildPropertiesToBeConverted($source) {
126 return array();
127 }
128
129 /**
130 * This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
131 *
132 * @param string $targetType
133 * @param string $propertyName
134 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
135 * @return string
136 * @api
137 */
138 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
139 }
140 }
141
142 ?>