[TASK] Streamline phpdoc annotations in EXT:extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / AbstractFileCollectionConverter.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 \TYPO3\CMS\Extbase\Domain\Model\File.
19 *
20 * @internal experimental! This class is experimental and subject to change!
21 */
22 abstract class AbstractFileCollectionConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
23 {
24 /**
25 * @var int
26 */
27 protected $priority = 10;
28
29 /**
30 * @var string
31 */
32 protected $expectedObjectType;
33
34 /**
35 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
36 */
37 protected $fileFactory;
38
39 /**
40 * @param \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory
41 */
42 public function injectFileFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory)
43 {
44 $this->fileFactory = $fileFactory;
45 }
46
47 /**
48 * Actually convert from $source to $targetType, taking into account the fully
49 * built $convertedChildProperties and $configuration.
50 *
51 * @param int $source
52 * @param string $targetType
53 * @param array $convertedChildProperties
54 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
55 * @throws \TYPO3\CMS\Extbase\Property\Exception
56 * @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileCollection
57 */
58 public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
59 {
60 $object = $this->getObject($source);
61 if (empty($this->expectedObjectType) || !$object instanceof $this->expectedObjectType) {
62 throw new \TYPO3\CMS\Extbase\Property\Exception('Expected object of type "' . $this->expectedObjectType . '" but got ' . get_class($object), 1342895976);
63 }
64 /** @var \TYPO3\CMS\Extbase\Domain\Model\AbstractFileCollection $subject */
65 $subject = $this->objectManager->get($targetType);
66 $subject->setObject($object);
67 return $subject;
68 }
69
70 /**
71 * @param int $source
72 * @return \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
73 */
74 abstract protected function getObject($source);
75 }