Made ObjectFactory really work
[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
37 $object = call_user_func_array('t3lib_div::makeInstance',$constructorArguments);
38
39 $injectVariables = array();
40 if (isset($this->injectors[$objectName])) {
41 $injectVariables = $this->injectors[$objectName];
42 } elseif (in_array('Tx_Fluid_Core_ViewHelperInterface',class_implements($objectName))) {
43 $injectVariables = $this->injectors['Tx_Fluid_Core_AbstractViewHelper'];
44 }
45
46 if (count($injectVariables)) {
47 foreach ($injectVariables as $injectMethodName => $objectName) {
48 call_user_func(array($object, $injectMethodName), $this->create($objectName));
49 }
50 }
51 return $object;
52 }
53 }
54
55 ?>