/** * Creates database connection instance * * @param array $database must have keys: dsn, user, password * @return \Dive\Connection\Connection */ public static function createDatabaseConnection(array $database) { $dsn = $database['dsn']; if (!isset(self::$connectionPoolTestClass[$dsn])) { $scheme = self::getSchemeFromDsn($dsn); /** @var \Dive\Connection\Driver\DriverInterface $driver */ $driver = self::createInstance('Connection\\Driver', 'Driver', $scheme); $conn = new Connection($driver, $dsn, $database['user'], $database['password']); $eventDispatcher = $conn->getEventDispatcher(); $eventDispatcher->addListener(Connection::EVENT_POST_INSERT, array(__CLASS__, 'addToDatasetRegistry')); $dbInit = new DbInit($conn, self::getSchema()); $dbInit->init(); self::$connectionPoolTestClass[$dsn] = $conn; } return self::$connectionPoolTestClass[$dsn]; }
/** * @return Event\EventDispatcherInterface */ public function getEventDispatcher() { return $this->conn->getEventDispatcher(); }
public function init() { $this->conn->getEventDispatcher()->addListener(Connection::EVENT_POST_CONNECT, array($this, 'initSchema')); }