[TASK] Backport Flow property mapper
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / ObjectStorageConverter.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 /**
25 * Converter which transforms simple types to a ObjectStorage.
26 *
27 * @api
28 * @todo Implement functionality for converting collection properties.
29 */
30 class ObjectStorageConverter extends AbstractTypeConverter {
31
32 /**
33 * @var array<string>
34 */
35 protected $sourceTypes = array('string', 'array');
36
37 /**
38 * @var string
39 */
40 protected $targetType = 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage';
41
42 /**
43 * @var integer
44 */
45 protected $priority = 1;
46
47 /**
48 * Actually convert from $source to $targetType, taking into account the fully
49 * built $convertedChildProperties and $configuration.
50 *
51 * @param mixed $source
52 * @param string $targetType
53 * @param array $convertedChildProperties
54 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
55 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
56 * @api
57 */
58 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
59 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
60 foreach ($convertedChildProperties as $subProperty) {
61 $objectStorage->attach($subProperty);
62 }
63 return $objectStorage;
64 }
65
66 /**
67 * Returns the source, if it is an array, otherwise an empty array.
68 *
69 * @param mixed $source
70 * @return array
71 * @api
72 */
73 public function getSourceChildPropertiesToBeConverted($source) {
74 if (is_array($source)) {
75 return $source;
76 }
77 return array();
78 }
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
87 * @api
88 */
89 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
90 $parsedTargetType = \TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::parseType($targetType);
91 return $parsedTargetType['elementType'];
92 }
93 }
94 ?>