[TASK] Backport Flow property mapper
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverterInterface.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Property;
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 * Interface for type converters, which can convert from a simple type to an object or another simple type.
25 *
26 * All Type Converters should have NO INTERNAL STATE, such that they can be used as singletons and multiple times in succession (as this improves performance dramatically).
27 *
28 * @api
29 */
30 interface TypeConverterInterface {
31
32 /**
33 * Returns the list of source types the TypeConverter can handle.
34 * Must be PHP simple types, classes or object is not allowed.
35 *
36 * @return array<string>
37 * @api
38 */
39 public function getSupportedSourceTypes();
40
41 /**
42 * Return the target type this TypeConverter converts to.
43 * Can be a simple type or a class name.
44 *
45 * @return string
46 * @api
47 */
48 public function getSupportedTargetType();
49
50 /**
51 * Returns the type for a given source, depending on e.g. the __type setting or other properties.
52 *
53 * @param mixed $source the source data
54 * @param string $originalTargetType the type we originally want to convert to
55 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
56 * @return string
57 * @api
58 */
59 public function getTargetTypeForSource($source, $originalTargetType, PropertyMappingConfigurationInterface $configuration = NULL);
60
61 /**
62 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
63 *
64 * @return integer
65 * @api
66 */
67 public function getPriority();
68
69 /**
70 * Here, the TypeConverter can do some additional runtime checks to see whether
71 * it can handle the given source data and the given target type.
72 *
73 * @param mixed $source the source data
74 * @param string $targetType the type to convert to.
75 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
76 * @api
77 */
78 public function canConvertFrom($source, $targetType);
79
80 /**
81 * Return a list of sub-properties inside the source object.
82 * The "key" is the sub-property name, and the "value" is the value of the sub-property.
83 *
84 * @param mixed $source
85 * @return array<mixed>
86 * @api
87 */
88 public function getSourceChildPropertiesToBeConverted($source);
89
90 /**
91 * Return the type of a given sub-property inside the $targetType
92 *
93 * @param string $targetType
94 * @param string $propertyName
95 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
96 * @return string the type of $propertyName in $targetType
97 * @api
98 */
99 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration);
100
101 /**
102 * Actually convert from $source to $targetType, taking into account the fully
103 * built $convertedChildProperties and $configuration.
104 *
105 * The return value can be one of three types:
106 * - an arbitrary object, or a simple type (which has been created while mapping).
107 * This is the normal case.
108 * - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur.
109 * - An instance of \TYPO3\CMS\Extbase\Error\Error -- This will be a user-visible error message later on.
110 * Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened.
111 *
112 * @param mixed $source
113 * @param string $targetType
114 * @param array $convertedChildProperties
115 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
116 * @return mixed|\TYPO3\CMS\Extbase\Error\Error the target type, or an error object if a user-error occurred
117 * @throws \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException thrown in case a developer error occurred
118 * @api
119 */
120 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL);
121 }
122 ?>