コード例 #1
0
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  * @expectedException \F3\FLOW3\Object\Exception
  */
 public function autoWiringThrowsExceptionForUnmatchedDependenciesOfRequiredSetterInjectedDependencies()
 {
     $this->mockObjectManager->expects($this->once())->method('getObject')->with('stdClass')->will($this->throwException(new \F3\FLOW3\Object\Exception()));
     $objectName = 'F3\\FLOW3\\Tests\\Object\\Fixture\\ClassWithUnmatchedRequiredSetterDependency';
     $setterParameters = array(array('position' => 0, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'allowsNull' => FALSE, 'class' => 'stdClass'));
     $this->mockReflectionService->expects($this->at(1))->method('getMethodParameters')->with($objectName, 'injectRequiredSetterArgument')->will($this->returnValue($setterParameters));
     $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration($objectName);
     $this->objectBuilder->createObject($objectName, $objectConfiguration);
 }
コード例 #2
0
 /**
  * Returns a fresh or existing instance of the object specified by $objectName.
  *
  * Important:
  *
  * If possible, instances of Prototype objects should always be created with the
  * Object Factory's create() method and Singleton objects should rather be
  * injected by some type of Dependency Injection.
  *
  * @param string $objectName The name of the object to return an instance of
  * @return object The object instance
  * @author Robert Lemke <*****@*****.**>
  * @throws \F3\FLOW3\Object\Exception\UnknownObjectException if an object with the given name does not exist
  * @api
  */
 public function getObject($objectName)
 {
     if (!$this->isObjectRegistered($objectName)) {
         throw new \F3\FLOW3\Object\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1166550023);
     }
     switch ($this->objectConfigurations[$objectName]->getScope()) {
         case 'prototype':
             $object = call_user_func_array(array($this->objectFactory, 'create'), func_get_args());
             break;
         case 'singleton':
             if ($this->singletonObjectsRegistry->objectExists($objectName)) {
                 $object = $this->singletonObjectsRegistry->getObject($objectName);
             } else {
                 $arguments = array_slice(func_get_args(), 1);
                 $overridingArguments = $this->getOverridingArguments($arguments);
                 $object = $this->objectBuilder->createObject($objectName, $this->objectConfigurations[$objectName], $overridingArguments);
                 $this->singletonObjectsRegistry->putObject($objectName, $object);
                 $this->registerShutdownObject($object, $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName());
             }
             break;
         case 'session':
             if ($this->sessionObjectsRegistry === NULL) {
                 throw new \F3\FLOW3\Object\Exception('The session objects registry has not been injected correctly into the object manager.', 1247211113);
             }
             if ($this->sessionObjectsRegistry->objectExists($objectName)) {
                 $object = $this->sessionObjectsRegistry->getObject($objectName);
             } else {
                 $arguments = array_slice(func_get_args(), 1);
                 $overridingArguments = $this->getOverridingArguments($arguments);
                 $object = $this->objectBuilder->createObject($objectName, $this->objectConfigurations[$objectName], $overridingArguments);
                 $this->sessionObjectsRegistry->putObject($objectName, $object);
                 $this->registerShutdownObject($object, $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName());
             }
             break;
     }
     return $object;
 }