‪TYPO3CMS  11.5
ObjectManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Container\ContainerInterface;
23 
31 {
35  private ‪$container;
36 
40  protected ‪$objectContainer;
41 
48  public function ‪__construct(ContainerInterface ‪$container, ExtbaseContainer ‪$objectContainer)
49  {
50  $this->container = ‪$container;
51  $this->objectContainer = ‪$objectContainer;
52  }
53 
68  public function ‪__sleep(): array
69  {
70  return [];
71  }
72 
82  public function ‪__wakeup()
83  {
84  $this->‪__construct(
85  GeneralUtility::getContainer(),
86  GeneralUtility::getContainer()->get(ExtbaseContainer::class)
87  );
88  }
89 
102  public function get(string $className, ...$constructorArguments): object
103  {
104  trigger_error('Class ' . __CLASS__ . ' is deprecated and will be removed in TYPO3 12.0', E_USER_DEPRECATED);
105  if ($className === \DateTime::class) {
106  return GeneralUtility::makeInstance($className, ...$constructorArguments);
107  }
108 
109  if ($this->container->has($className)) {
110  if ($constructorArguments === []) {
111  $instance = $this->container->get($className);
112  if (!is_object($instance)) {
113  throw new ‪Exception('Invalid object name "' . $className . '". The PSR-11 container entry resolves to a non object.', 1562357346);
114  }
115  return $instance;
116  }
117  trigger_error($className . ' is available in the PSR-11 container. That means you should not try to instanciate it using constructor arguments. Falling back to legacy extbase based injection.', E_USER_DEPRECATED);
118  }
119 
120  return $this->objectContainer->getInstance($className, $constructorArguments);
121  }
122 
135  public function ‪getEmptyObject(string $className): object
136  {
137  return $this->objectContainer->getEmptyObject($className);
138  }
139 }
‪TYPO3\CMS\Extbase\Object\ObjectManager\__construct
‪__construct(ContainerInterface $container, ExtbaseContainer $objectContainer)
Definition: ObjectManager.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager\$container
‪ContainerInterface $container
Definition: ObjectManager.php:34
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:42
‪TYPO3\CMS\Extbase\Object\ObjectManager\__sleep
‪array __sleep()
Definition: ObjectManager.php:66
‪TYPO3\CMS\Extbase\Object\ObjectManager\$objectContainer
‪ExtbaseContainer $objectContainer
Definition: ObjectManager.php:38
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:29
‪TYPO3\CMS\Extbase\Object\ObjectManager\getEmptyObject
‪T getEmptyObject(string $className)
Definition: ObjectManager.php:133
‪TYPO3\CMS\Extbase\Object\ObjectManager\__wakeup
‪__wakeup()
Definition: ObjectManager.php:80
‪TYPO3\CMS\Extbase\Object\Exception
Definition: Exception.php:27
‪TYPO3\CMS\Extbase\Object
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:31