[FEATURE] Add ObjectManager->getScope like in TYPO3.Flow
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Object / ObjectManager.php
index 2dbc430..d2e808a 100644 (file)
@@ -27,6 +27,9 @@ namespace TYPO3\CMS\Extbase\Object;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
+use \TYPO3\CMS\Extbase\Object\Container\Container;
+
 /**
  * Implementation of the default Extbase Object Manager
  */
@@ -107,6 +110,21 @@ class ObjectManager implements ObjectManagerInterface {
                return $instance;
        }
 
+       /**
+        * Returns the scope of the specified object.
+        *
+        * @param string $objectName The object name
+        * @return integer One of the Container::SCOPE_ constants
+        * @throws \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException
+        * @api
+        */
+       public function getScope($objectName) {
+               if (!$this->isRegistered($objectName)) {
+                       throw new \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1265367590);
+               }
+               return $this->objectContainer->isSingleton($objectName) ? Container::SCOPE_SINGLETON : Container::SCOPE_PROTOTYPE;
+       }
+
        /**
         * Creates a fresh instance of the object specified by $objectName.
         *