[TASK] Streamline phpdoc annotations in EXT:extbase
[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 file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Converter which transforms simple types to an ObjectStorage.
19 *
20 * @todo Implement functionality for converting collection properties.
21 */
22 class ObjectStorageConverter extends AbstractTypeConverter
23 {
24 /**
25 * @var array<string>
26 */
27 protected $sourceTypes = ['string', 'array'];
28
29 /**
30 * @var string
31 */
32 protected $targetType = \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class;
33
34 /**
35 * @var int
36 */
37 protected $priority = 10;
38
39 /**
40 * Actually convert from $source to $targetType, taking into account the fully
41 * built $convertedChildProperties and $configuration.
42 *
43 * @param mixed $source
44 * @param string $targetType
45 * @param array $convertedChildProperties
46 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
47 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
48 */
49 public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
50 {
51 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
52 foreach ($convertedChildProperties as $subProperty) {
53 $objectStorage->attach($subProperty);
54 }
55 return $objectStorage;
56 }
57
58 /**
59 * Returns the source, if it is an array, otherwise an empty array.
60 *
61 * @param mixed $source
62 * @return array
63 */
64 public function getSourceChildPropertiesToBeConverted($source)
65 {
66 if (is_array($source)) {
67 return $source;
68 }
69 return [];
70 }
71
72 /**
73 * Return the type of a given sub-property inside the $targetType
74 *
75 * @param string $targetType
76 * @param string $propertyName
77 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
78 * @return string
79 */
80 public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
81 {
82 $parsedTargetType = \TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::parseType($targetType);
83 return $parsedTargetType['elementType'];
84 }
85 }