[FEATURE] Integrate basic file abstraction layer models
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / AbstractFileCollectionConverter.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Converter which transforms simple types to Tx_Extbase_Domain_Model_File.
27 *
28 * @api experimental! This class is experimental and subject to change!
29 */
30 abstract class Tx_Extbase_Property_TypeConverter_AbstractFileCollectionConverter extends Tx_Extbase_Property_TypeConverter_AbstractTypeConverter {
31 /**
32 * @var integer
33 */
34 protected $priority = 1;
35
36 /**
37 * @var string
38 */
39 protected $expectedObjectType;
40
41 /**
42 * @var t3lib_file_Factory
43 */
44 protected $fileFactory;
45
46 /**
47 * @param t3lib_file_Factory $fileFactory
48 */
49 public function injectFileFactory(t3lib_file_Factory $fileFactory) {
50 $this->fileFactory = $fileFactory;
51 }
52
53 /**
54 * Actually convert from $source to $targetType, taking into account the fully
55 * built $convertedChildProperties and $configuration.
56 *
57 * @param integer $source
58 * @param string $targetType
59 * @param array $convertedChildProperties
60 * @param Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration
61 * @return Tx_Extbase_Domain_Model_AbstractFileCollection
62 * @api
63 */
64 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration = NULL) {
65 $object = $this->getObject($source);
66
67 if (empty($this->expectedObjectType) || !$object instanceof $this->expectedObjectType) {
68 throw new Tx_Extbase_Property_Exception(
69 'Expected object of type "' . $this->expectedObjectType . '" but got ' . get_class($object),
70 1342895975
71 );
72 }
73
74 /** @var $subject Tx_Extbase_Domain_Model_AbstractFileCollection */
75 $subject = $this->objectManager->create($targetType);
76 $subject->setObject($object);
77
78 return $subject;
79 }
80
81 /**
82 * @param integer $source
83 * @return t3lib_file_Collection_AbstractFileCollection
84 */
85 abstract protected function getObject($source);
86 }
87 ?>