Ejemplo 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);
 }
Ejemplo 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'));
 }
Ejemplo n.º 3
0
 public function testConnectionOld()
 {
     $config = ['database' => 'reach_testing', 'host' => 'localhost', 'port' => 27017, 'options' => ['connect' => true, 'socketTimeoutMS' => 60000]];
     ConnectionManager::registerConnection($config);
     $connection = ConnectionManager::getConnection();
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection);
     $this->assertTrue(method_exists($connection, 'getDb'));
     $this->assertInstanceOf('\\MongoDB', $connection->getDb());
     $config2 = ['database' => 'reach_testing2'];
     Container::register('another', $config2, '\\Reach\\Mongo\\Connection');
     $connection2 = Container::get('another');
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection2);
     $this->assertEquals('reach_testing2', $connection2->getDbName());
     $connection = ConnectionManager::getConnection();
     $this->assertInstanceOf('\\Reach\\Mongo\\Connection', $connection);
     $this->assertEquals('reach_testing', $connection->getDbName());
 }
Ejemplo n.º 4
0
 public function testAnotherConnection()
 {
     $model = TestSchema::getCollection('another')->findOne();
     $this->assertNull($model);
     $model = new TestSchema(['title' => '123']);
     $model->setConnectionName('another')->save();
     $model = TestSchema::getCollection('another')->findOne($model->_id);
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $model);
     $this->assertEquals('123', $model->title);
     \Reach\Service\Container::get('another')->selectDB('reach_testing2')->drop();
     \Reach\Service\Container::get('another')->close();
 }
Ejemplo n.º 5
0
 public static function setUpBeforeClass()
 {
     self::$config = ['class' => '\\Reach\\Sphinx\\Connection', 'host' => 'localhost', 'port' => 9312];
     \Reach\Service\Container::register('sphinx', self::$config);
     self::$connection = \Reach\Service\Container::get('sphinx');
 }