ad9270955b8d25b5a4039ffe22224d2d01171b24
[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 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 * @api
30 */
31 interface TypeConverterInterface {
32
33 /**
34 * Returns the list of source types the TypeConverter can handle.
35 * Must be PHP simple types, classes or object is not allowed.
36 *
37 * @return array<string>
38 * @api
39 */
40 public function getSupportedSourceTypes();
41
42 /**
43 * Return the target type this TypeConverter converts to.
44 * Can be a simple type or a class name.
45 *
46 * @return string
47 * @api
48 */
49 public function getSupportedTargetType();
50
51 /**
52 * Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
53 *
54 * @return integer
55 * @api
56 */
57 public function getPriority();
58
59 /**
60 * Here, the TypeConverter can do some additional runtime checks to see whether
61 * it can handle the given source data and the given target type.
62 *
63 * @param mixed $source the source data
64 * @param string $targetType the type to convert to.
65 * @return boolean TRUE if this TypeConverter can convert from $source to $targetType, FALSE otherwise.
66 * @api
67 */
68 public function canConvertFrom($source, $targetType);
69
70 /**
71 * Return a list of sub-properties inside the source object.
72 * The "key" is the sub-property name, and the "value" is the value of the sub-property.
73 *
74 * @param mixed $source
75 * @return array<mixed>
76 * @api
77 */
78 public function getSourceChildPropertiesToBeConverted($source);
79
80 /**
81 * Return the type of a given sub-property inside the $targetType
82 *
83 * @param string $targetType
84 * @param string $propertyName
85 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
86 * @return string the type of $propertyName in $targetType
87 * @api
88 */
89 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration);
90
91 /**
92 * Actually convert from $source to $targetType, taking into account the fully
93 * built $convertedChildProperties and $configuration.
94 *
95 * The return value can be one of three types:
96 * - an arbitrary object, or a simple type (which has been created while mapping).
97 * This is the normal case.
98 * - 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.
99 * - An instance of \TYPO3\CMS\Extbase\Error\Error - This will be a user-visible error message lateron.
100 * Furthermore, it should throw an Exception if an unexpected failure occured or a configuration issue happened.
101 *
102 * @param mixed $source
103 * @param string $targetType
104 * @param array $convertedChildProperties
105 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
106 * @return mixed the target type
107 * @api
108 */
109 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL);
110 }
111
112 ?>