コード例 #1
0
ファイル: DITest.php プロジェクト: panlatent/pure
 public function testSet()
 {
     $container = new \Pure\Container();
     $di = new \Pure\DI($container, $this->provider);
     $di->set('object2', $this);
     $this->assertSame($this, $this->provider->get('object2'));
 }
コード例 #2
0
ファイル: DI.php プロジェクト: panlatent/pure
 /**
  * 获取一个已注册的服务对象
  *
  * @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;
 }