a7c53e785013852ae84bf39689970e9ca268bca4
[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 * Converter which transforms arrays to arrays.
25 *
26 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
27 * @api
28 */
29 class ObjectStorageConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter implements \TYPO3\CMS\Core\SingletonInterface {
30
31 /**
32 * @var \TYPO3\CMS\Extbase\Service\TypeHandlingService
33 */
34 protected $typeHandlingService;
35
36 /**
37 * @param \TYPO3\CMS\Extbase\Service\TypeHandlingService $typeHandlingService
38 * @return void
39 */
40 public function injectTypeHandlingService(\TYPO3\CMS\Extbase\Service\TypeHandlingService $typeHandlingService) {
41 $this->typeHandlingService = $typeHandlingService;
42 }
43
44 /**
45 * @var array<string>
46 */
47 protected $sourceTypes = array('string', 'array');
48
49 /**
50 * @var string
51 */
52 protected $targetType = 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage';
53
54 /**
55 * @var integer
56 */
57 protected $priority = 1;
58
59 /**
60 * Returns the source, if it is an array, otherwise an empty array.
61 *
62 * @param mixed $source
63 * @return array
64 * @api
65 */
66 public function getSourceChildPropertiesToBeConverted($source) {
67 if (is_array($source)) {
68 return $source;
69 }
70 return array();
71 }
72
73 /**
74 * Actually convert from $source to $targetType, in fact a noop here.
75 *
76 * @param array $source
77 * @param string $targetType
78 * @param array $convertedChildProperties
79 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
80 * @return array
81 * @api
82 */
83 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
84 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
85 foreach ($convertedChildProperties as $subProperty) {
86 $objectStorage->attach($subProperty);
87 }
88 return $objectStorage;
89 }
90
91 /**
92 * Return the type of a given sub-property inside the $targetType
93 *
94 * @param string $targetType
95 * @param string $propertyName
96 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
97 * @return string
98 * @api
99 */
100 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration) {
101 $parsedTargetType = $this->typeHandlingService->parseType($targetType);
102 return $parsedTargetType['elementType'];
103 }
104 }
105
106 ?>