Exemplo n.º 1
0
 /**
  * 获取一个已注册的服务对象
  *
  * @param string $name
  * @return mixed
  * @throws \Pure\DI\Exception
  */
 public function get($name)
 {
     if ($this->_container->has($name)) {
         return $this->_container->get($name);
     }
     try {
         $object = $this->_provider->get($name);
         $this->_container->set($name, $object);
     } catch (Exception $e) {
         throw new Exception("DI component cannot provide '{$name}' service: {$e->getMessage()}");
     }
     return $object;
 }
Exemplo n.º 2
0
 public function set($name, $value)
 {
     if (!is_object($value) && !is_string($value) && !is_callable($value)) {
         throw new Exception("被设置的值不是一个有效的数据类型");
     }
     parent::set($name, $value);
 }