Пример #1
0
 /**
  * Create the instance with loop detection
  *
  * Loop: an instance depends on itself in the creation chain.
  *
  * @param  string $rawId
  * @param  array $args arguments for the constructor if any
  * @return object
  * @throws LogicException if instantiation goes wrong or loop detected
  * @access protected
  */
 protected function createInstance($rawId, array $args)
 {
     // conver 'service_id' to '#service_id'
     $serviceId = ObjectResolver::getServiceId($rawId);
     if (isset($this->loop[$serviceId])) {
         throw new LogicException(Message::get(Message::DI_LOOP_DETECTED, $rawId), Message::DI_LOOP_DETECTED);
     } else {
         $this->loop[$serviceId] = ++$this->counter;
         $obj = $this->getFactory()->createInstance($rawId, $args);
         unset($this->loop[$serviceId]);
         return $obj;
     }
 }
Пример #2
0
 /**
  * Get an object base on provided classname or interface name
  *
  * @param  string $classname class or interface name
  * @return object
  * @throws \Exception if something goes wrong
  * @access protected
  */
 protected function getObjectByClass($classname)
 {
     if ($this->getResolver()->hasService($classname)) {
         $serviceId = ObjectResolver::getServiceId($classname);
         return $this->getResolver()->get($serviceId);
     }
     throw new LogicException(Message::get(Message::DI_CLASS_UNKNOWN, $classname), Message::DI_CLASS_UNKNOWN);
 }