TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ObjectManager.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Object;
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 
18 
23 {
27  protected $objectContainer;
28 
32  public function __construct()
33  {
34  $this->objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
35  }
36 
50  public function __sleep()
51  {
52  // Use get_objects_vars() instead of
53  // a much more expensive Reflection:
54  $properties = get_object_vars($this);
55  unset($properties['objectContainer']);
56  return array_keys($properties);
57  }
58 
68  public function __wakeup()
69  {
70  $this->__construct();
71  }
72 
79  public function isRegistered($objectName)
80  {
81  return class_exists($objectName, true);
82  }
83 
91  public function get($objectName)
92  {
93  $arguments = func_get_args();
94  array_shift($arguments);
95  if ($objectName === 'DateTime') {
96  array_unshift($arguments, $objectName);
97  $instance = call_user_func_array([\TYPO3\CMS\Core\Utility\GeneralUtility::class, 'makeInstance'], $arguments);
98  } else {
99  $instance = $this->objectContainer->getInstance($objectName, $arguments);
100  }
101  return $instance;
102  }
103 
112  public function getScope($objectName)
113  {
114  if (!$this->isRegistered($objectName)) {
115  throw new \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1265367590);
116  }
117  return $this->objectContainer->isSingleton($objectName) ? Container::SCOPE_SINGLETON : Container::SCOPE_PROTOTYPE;
118  }
119 
127  public function getEmptyObject($className)
128  {
129  return $this->objectContainer->getEmptyObject($className);
130  }
131 }
static makeInstance($className,...$constructorArguments)