5789a958277f4c920ba6b10e97472ff6363de0c9
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Compatibility / ObjectFactory.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
15
16 /**
17 * @package
18 * @subpackage
19 * @version $Id:$
20 */
21
22 class Tx_Fluid_Compatibility_ObjectFactory implements t3lib_Singleton {
23
24 protected $injectors = array(
25 'Tx_Fluid_Core_AbstractViewHelper' => array(
26 'injectValidatorResolver' => 'Tx_Fluid_Compatibility_Validation_ValidatorResolver',
27 'injectReflectionService' => 'Tx_ExtBase_Reflection_Service'
28 ),
29 'Tx_Fluid_Core_ParsingState' => array('injectVariableContainer' => 'Tx_Fluid_Core_VariableContainer'),
30 'Tx_Fluid_Core_TemplateParser' => array('injectObjectFactory' => 'Tx_Fluid_Compatibility_ObjectFactory'),
31 'Tx_Fluid_Core_VariableContainer' => array('injectObjectFactory' => 'Tx_Fluid_Compatibility_ObjectFactory'),
32 );
33
34 public function create($objectName) {
35 $constructorArguments = func_get_args();
36 array_shift($constructorArguments);
37
38 if (count($constructorArguments)) {
39 $reflectedClass = new ReflectionClass($objectName);
40 $object = $reflectedClass->newInstanceArgs($constructorArguments);
41 } else {
42 $object = new $objectName;
43 }
44
45 $injectVariables = array();
46 if (isset($this->injectors[$objectName])) {
47 $injectVariables = $this->injectors[$objectName];
48 } elseif (in_array('Tx_Fluid_Core_ViewHelperInterface',class_implements($objectName))) {
49 $injectVariables = $this->injectors['Tx_Fluid_Core_AbstractViewHelper'];
50 }
51
52 if (count($injectVariables)) {
53 foreach ($injectVariables as $injectMethodName => $objectName) {
54 call_user_func(array($object, $injectMethodName), $this->create($objectName));
55 }
56 }
57 return $object;
58 }
59 }
60
61 ?>