addConnection() public method

Adds a new connection to the pool.
public addConnection ( Connection $conn ) : boolean
$conn Connection The actual connection that will be added to the pool.
return boolean Success
 /**
  * Register MongoDbConnector within the application.
  *
  * @return void
  */
 public function registerConnector()
 {
     $config = $this->app->make('config');
     MongolidIoc::setContainer($this->app);
     $connectionString = $this->buildConnectionString();
     $connection = new Connection($connectionString);
     $pool = new Pool();
     $eventService = new EventTriggerService();
     $eventService->registerEventDispatcher($this->app->make(LaravelEventTrigger::class));
     $pool->addConnection($connection);
     $this->app->instance(Pool::class, $pool);
     $this->app->instance(EventTriggerService::class, $eventService);
     $this->app->bind(CacheComponentInterface::class, function ($app) {
         return new LaravelCacheComponent($app[CacheRepository::class], $app[Serializer::class]);
     });
     $connection->defaultDatabase = $config->get('database.mongodb.default.database', 'mongolid');
 }
Ejemplo n.º 2
0
 /**
  * Main entry point to openning a connection and start using Mongolid in
  * pure PHP. After adding a connection into the Manager you are ready to
  * persist and query your models.
  *
  * @param Connection $connection Connection instance to be used in database interactions.
  *
  * @return bool Success
  */
 public function addConnection(Connection $connection) : bool
 {
     $this->init();
     $this->connectionPool->addConnection($connection);
     return true;
 }