Esempio n. 1
0
 /**
  * @param string $connection_name
  * @return mixed
  */
 public static function getConnection($connection_name = null)
 {
     if (empty($connection_name)) {
         $connection_name = self::$default_connection_name;
     }
     if (!ServiceContainer::has($connection_name)) {
         throw new InvalidArgumentException("Reach service \"{$connection_name}\" is not defined.");
     }
     return ServiceContainer::get($connection_name);
 }
Esempio n. 2
0
 public function testConstruct()
 {
     $config = ['class' => '\\Reach\\Connection\\Dummy', 'host' => 'localhost'];
     \Reach\Service\Container::register('connection', $config);
     $connection = \Reach\Service\Container::get('connection');
     $this->assertInstanceOf('\\Reach\\Connection\\Dummy', $connection);
     $connection = new \Reach\Connection\Dummy($config);
     \Reach\Service\Container::set('connection', $connection);
     $this->assertInstanceOf('\\Reach\\Connection\\Dummy', \Reach\Service\Container::get('connection'));
     $this->assertTrue(\Reach\Service\Container::has('connection'));
 }