Doctrine\MongoDB\Connection::initialize PHP Method

initialize() public method

This method will dispatch preConnect and postConnect events.
public initialize ( )
    public function initialize()
    {
        if ($this->mongoClient !== null) {
            return;
        }
        if ($this->eventManager->hasListeners(Events::preConnect)) {
            $this->eventManager->dispatchEvent(Events::preConnect, new EventArgs($this));
        }
        $server = $this->server ?: 'mongodb://localhost:27017';
        $options = $this->options;
        $options = isset($options['timeout']) ? $this->convertConnectTimeout($options) : $options;
        $options = isset($options['wTimeout']) ? $this->convertWriteTimeout($options) : $options;
        $this->mongoClient = $this->retry(function () use($server, $options) {
            return new \MongoClient($server, $options, $this->driverOptions);
        });
        if ($this->eventManager->hasListeners(Events::postConnect)) {
            $this->eventManager->dispatchEvent(Events::postConnect, new EventArgs($this));
        }
    }

Usage Example

Beispiel #1
0
 public function testInitialize()
 {
     $conn = new Connection();
     $this->assertNull($conn->getMongo());
     $conn->initialize();
     $this->assertInstanceOf('Mongo', $conn->getMongo());
 }
All Usage Examples Of Doctrine\MongoDB\Connection::initialize