TYPO3 CMS  TYPO3_7-6
ObjectManagerException.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 
21 {
25  protected $objectContainer;
26 
30  public function __construct()
31  {
32  $this->objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
33  }
34 
48  public function __sleep()
49  {
50  // Use get_objects_vars() instead of
51  // a much more expensive Reflection:
52  $properties = get_object_vars($this);
53  unset($properties['objectContainer']);
54  return array_keys($properties);
55  }
56 
66  public function __wakeup()
67  {
68  $this->__construct();
69  }
70 
77  public function isRegistered($objectName)
78  {
79  return class_exists($objectName, true);
80  }
81 
95  public function get($objectName)
96  {
97  $arguments = func_get_args();
98  array_shift($arguments);
99  return $this->objectContainer->getInstance($objectName, $arguments);
100  }
101 
115  public function create($objectName)
116  {
117  $arguments = func_get_args();
118  array_shift($arguments);
119  if ($objectName === 'DateTime') {
120  array_unshift($arguments, $objectName);
121  $instance = call_user_func_array([\TYPO3\CMS\Core\Utility\GeneralUtility::class, 'makeInstance'], $arguments);
122  } else {
123  $instance = $this->objectContainer->getInstance($objectName, $arguments);
124  }
125  if ($instance instanceof \TYPO3\CMS\Core\SingletonInterface) {
126  throw new \TYPO3\CMS\Extbase\Object\Exception\WrongScopeException('Object "' . $objectName . '" is of not of scope prototype, but only prototype is supported by create()', 1265203124);
127  }
128  return $instance;
129  }
130 
138  public function getEmptyObject($className)
139  {
140  return $this->objectContainer->getEmptyObject($className);
141  }
142 }