Merge "[BUGFIX] ConfigurationManager use FrontendSimulator only if neccessary"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / ObjectStorageConverter.php
1 <?php
2
3 /* *
4 * This script belongs to the Extbase framework *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
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 Tx_Extbase_Property_TypeConverter_ObjectStorageConverter extends Tx_Extbase_Property_TypeConverter_AbstractTypeConverter implements t3lib_Singleton {
30
31 /**
32 * @var Tx_Extbase_Service_TypeHandlingService
33 */
34 protected $typeHandlingService;
35
36 /**
37 * @param Tx_Extbase_Service_TypeHandlingService $typeHandlingService
38 * @return void
39 */
40 public function injectTypeHandlingService(Tx_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 = 'Tx_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 * @return array
63 * @api
64 */
65 public function getSourceChildPropertiesToBeConverted($source) {
66 if (is_array($source)) {
67 return $source;
68 }
69 return array();
70 }
71
72 /**
73 * Actually convert from $source to $targetType, in fact a noop here.
74 *
75 * @param array $source
76 * @param string $targetType
77 * @param array $convertedChildProperties
78 * @param Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration
79 * @return array
80 * @api
81 */
82 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration = NULL) {
83 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
84
85 foreach ($convertedChildProperties as $subProperty) {
86 $objectStorage->attach($subProperty);
87 }
88
89 return $objectStorage;
90 }
91
92 /**
93 * Return the type of a given sub-property inside the $targetType
94 *
95 * @param string $targetType
96 * @param string $propertyName
97 * @param Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration
98 * @return string
99 * @api
100 */
101 public function getTypeOfChildProperty($targetType, $propertyName, Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration) {
102
103 $parsedTargetType = $this->typeHandlingService->parseType($targetType);
104 return $parsedTargetType['elementType'];
105 }
106 }
107 ?>