‪TYPO3CMS  9.5
ObjectManager.php
Go to the documentation of this file.
1 <?php
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 
25 {
29  protected ‪$objectContainer;
30 
34  public function ‪__construct()
35  {
36  $this->objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\‪Container\Container::class);
37  }
38 
53  public function ‪__sleep()
54  {
55  // Use get_objects_vars() instead of
56  // a much more expensive Reflection:
57  $properties = get_object_vars($this);
58  unset($properties['objectContainer']);
59  return array_keys($properties);
60  }
61 
71  public function ‪__wakeup()
72  {
73  $this->‪__construct();
74  }
75 
83  public function ‪isRegistered($objectName)
84  {
85  return class_exists($objectName, true);
86  }
87 
95  public function get($objectName, ...$constructorArguments)
96  {
97  if ($objectName === 'DateTime') {
98  $instance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($objectName, ...$constructorArguments);
99  } else {
100  $instance = $this->objectContainer->getInstance($objectName, $constructorArguments);
101  }
102  return $instance;
103  }
104 
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 
126  public function ‪getEmptyObject($className)
127  {
128  return $this->objectContainer->getEmptyObject($className);
129  }
130 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:30
‪TYPO3\CMS\Extbase\Object\ObjectManager\getScope
‪int getScope($objectName)
Definition: ObjectManager.php:111
‪TYPO3\CMS\Extbase\Object\ObjectManager\__construct
‪__construct()
Definition: ObjectManager.php:33
‪TYPO3
‪TYPO3\CMS\Extbase\Object\ObjectManager\__sleep
‪array __sleep()
Definition: ObjectManager.php:52
‪TYPO3\CMS\Extbase\Object\ObjectManager\getEmptyObject
‪object &T getEmptyObject($className)
Definition: ObjectManager.php:125
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:23
‪TYPO3\CMS\Extbase\Object\ObjectManager\isRegistered
‪bool isRegistered($objectName)
Definition: ObjectManager.php:82
‪TYPO3\CMS\Extbase\Object\Container\Container\SCOPE_PROTOTYPE
‪const SCOPE_PROTOTYPE
Definition: Container.php:31
‪TYPO3\CMS\Extbase\Object\ObjectManager\__wakeup
‪__wakeup()
Definition: ObjectManager.php:70
‪TYPO3\CMS\Extbase\Object\Container\Container\SCOPE_SINGLETON
‪const SCOPE_SINGLETON
Definition: Container.php:32
‪TYPO3\CMS\Extbase\Object
‪TYPO3\CMS\Extbase\Object\ObjectManager\$objectContainer
‪TYPO3 CMS Extbase Object Container Container $objectContainer
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25