/**
  * @test
  * @author  Robert Lemke <*****@*****.**>
  */
 public function objectExistsReturnsCorrectResult()
 {
     $originalObject = new \F3\FLOW3\Fixture\DummyClass();
     $this->assertFalse($this->objectRegistry->objectExists('DummyObject'), 'objectExists() did not return FALSE although the object should not exist yet.');
     $this->objectRegistry->putObject('DummyObject', $originalObject);
     $this->assertTrue($this->objectRegistry->objectExists('DummyObject'), 'objectExists() did not return TRUE although the object should exist.');
 }
Ejemplo n.º 2
0
 /**
  * Registers the given class as an object.
  *
  * Note: When registering an object after FLOW3 has been initialized, it
  * won't get picked up by AOP, so do not expect to be able to register
  * entities or anything else relying in AOP to work.
  *
  * @param string $objectName The unique identifier of the object
  * @param string $className The class name which provides the functionality for this object. Same as object name by default.
  * @param object $object If the object has been instantiated prior to registration (which should be avoided whenever possible), it can be passed here.
  * @return void
  * @author Robert Lemke <*****@*****.**>
  * @throws \F3\FLOW3\Object\Exception\ObjectAlreadyRegisteredException if the object has already been registered
  * @throws \F3\FLOW3\Object\Exception\InvalidObjectException if the passed $object is not a valid instance of $className
  * @api
  */
 public function registerObject($objectName, $className = NULL, $object = NULL)
 {
     if ($this->isObjectRegistered($objectName)) {
         throw new \F3\FLOW3\Object\Exception\ObjectAlreadyRegisteredException('The object ' . $objectName . ' is already registered.', 1184160573);
     }
     if ($className === NULL) {
         $className = $objectName;
     }
     if (!class_exists($className, TRUE) || interface_exists($className)) {
         throw new \F3\FLOW3\Object\Exception\UnknownClassException('The specified class "' . $className . '" does not exist (or is no class) and therefore cannot be registered as an object.', 1200239063);
     }
     if ($object !== NULL) {
         if (!is_object($object) || !$object instanceof $className) {
             throw new \F3\FLOW3\Object\Exception\InvalidObjectException('The object instance must be a valid instance of the specified class (' . $className . ').', 1183742379);
         }
         $this->singletonObjectsRegistry->putObject($objectName, $object);
     }
     $this->objectConfigurations[$objectName] = new \F3\FLOW3\Object\Configuration\Configuration($objectName, $className);
     if ($this->reflectionService->isClassTaggedWith($className, 'scope')) {
         $scope = trim(implode('', $this->reflectionService->getClassTagValues($className, 'scope')));
         $this->objectConfigurations[$objectName]->setScope($scope);
     }
     $this->registeredObjects[$objectName] = strtolower($objectName);
     $this->registeredClasses[$className] = $objectName;
 }