2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Implementation of the default Extbase Object Manager
34 class Tx_Extbase_Object_ObjectManager
implements Tx_Extbase_Object_ObjectManagerInterface
{
37 * @var Tx_Container_Container
39 protected $objectContainer;
42 * Constructs a new Object Manager
44 public function __construct() {
45 $this->objectContainer
= Tx_Container_Container
::getContainer();
49 * Returns a fresh or existing instance of the object specified by $objectName.
53 * If possible, instances of Prototype objects should always be created with the
54 * Object Manager's create() method and Singleton objects should rather be
55 * injected by some type of Dependency Injection.
57 * @param string $objectName The name of the object to return an instance of
58 * @return object The object instance
61 public function get($objectName) {
62 $arguments = func_get_args();
63 return call_user_func_array(array($this->objectContainer
, 'getInstance'), $arguments);
67 * Creates a fresh instance of the object specified by $objectName.
69 * This factory method can only create objects of the scope prototype.
70 * Singleton objects must be either injected by some type of Dependency Injection or
71 * if that is not possible, be retrieved by the get() method of the
74 * @param string $objectName The name of the object to create
75 * @return object The new object instance
76 * @throws Tx_Extbase_Object_Exception_WrongScropeException if the created object is not of scope prototype
79 public function create($objectName) {
80 $arguments = func_get_args();
81 $instance = call_user_func_array(array($this->objectContainer
, 'getInstance'), $arguments);
83 if ($instance instanceof t3lib_Singleton
) {
84 throw new Tx_Extbase_Object_Exception_WrongScope('Object "' . $objectName . '" is of not of scope prototype, but only prototype is supported by create()', 1265203124);
91 * Registers a classname that should be used to resolve a given interface.
93 * Per default the interface's name stripped of "Interface" will be used.
94 * @param string $className
95 * @param string $alternativeClassName
97 static public function registerImplementation($className, $alternativeClassName) {
98 return Tx_Container_Container
::getContainer()->registerImplementation($className, $alternativeClassName);