TYPO3 CMS  TYPO3_6-2
ObjectManager.php
Go to the documentation of this file.
1 <?php
3 
17 use \TYPO3\CMS\Extbase\Object\Container\Container;
18 
23 
27  protected $objectContainer;
28 
32  public function __construct() {
33  $this->objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\Container');
34  }
35 
49  public function __sleep() {
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  $this->__construct();
68  }
69 
76  public function isRegistered($objectName) {
77  return class_exists($objectName, TRUE);
78  }
79 
87  public function get($objectName) {
88  $arguments = func_get_args();
89  array_shift($arguments);
90  if ($objectName === 'DateTime') {
91  array_unshift($arguments, $objectName);
92  $instance = call_user_func_array(array('TYPO3\\CMS\\Core\\Utility\\GeneralUtility', 'makeInstance'), $arguments);
93  } else {
94  $instance = $this->objectContainer->getInstance($objectName, $arguments);
95  }
96  return $instance;
97  }
98 
107  public function getScope($objectName) {
108  if (!$this->isRegistered($objectName)) {
109  throw new \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1265367590);
110  }
111  return $this->objectContainer->isSingleton($objectName) ? Container::SCOPE_SINGLETON : Container::SCOPE_PROTOTYPE;
112  }
113 
126  public function create($objectName) {
128  $arguments = func_get_args();
129  $instance = call_user_func_array(array($this, 'get'), $arguments);
130  return $instance;
131  }
132 
140  public function getEmptyObject($className) {
141  return $this->objectContainer->getEmptyObject($className);
142  }
143 }