Commit 75ea33ac by Alexander Mohorev

mongodb method "open" not triggered event "after open connection"

parent e1b55153
...@@ -73,6 +73,11 @@ use Yii; ...@@ -73,6 +73,11 @@ use Yii;
class Connection extends Component class Connection extends Component
{ {
/** /**
* @event Event an event that is triggered after a DB connection is established
*/
const EVENT_AFTER_OPEN = 'afterOpen';
/**
* @var string host:port * @var string host:port
* *
* Correct syntax is: * Correct syntax is:
...@@ -233,6 +238,7 @@ class Connection extends Component ...@@ -233,6 +238,7 @@ class Connection extends Component
$options['db'] = $this->defaultDatabaseName; $options['db'] = $this->defaultDatabaseName;
} }
$this->mongoClient = new \MongoClient($this->dsn, $options); $this->mongoClient = new \MongoClient($this->dsn, $options);
$this->initConnection();
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
...@@ -253,4 +259,14 @@ class Connection extends Component ...@@ -253,4 +259,14 @@ class Connection extends Component
$this->_databases = []; $this->_databases = [];
} }
} }
/**
* Initializes the DB connection.
* This method is invoked right after the DB connection is established.
* The default implementation triggers an [[EVENT_AFTER_OPEN]] event.
*/
protected function initConnection()
{
$this->trigger(self::EVENT_AFTER_OPEN);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment