_connection = $connection; $this->_connection_fetchmode = $fetchMode; $this->setFetchMode($fetchMode); parent::__construct($container); } /** * Build the database manager instance. * * @return void */ protected function setupManager() { $factory = new ConnectionFactory($this->container); $this->manager = new DatabaseManager($this->container, $factory); $this->manager->addDefaultConnection($this->_connection, $this->_connection_fetchmode); } /** * Get a query builder instance. * > Use extended QueryBuilder * * @param string $table * @param string $as * @param string $connection * @return QueryBuilder */ public static function table($table, $as = null, $connection = null) { return static::$instance->connection($connection)->table($table, $as); } /** * Static init with existing connection * * @param PDO $connection * @param integer $fetchMode * @param Container|null $container * @return static */ public static function init(PDO $connection, $fetchMode = PDO::FETCH_ASSOC, Container $container = null) { $capsule = new static($connection, $fetchMode, $container); $dispatcher = new Dispatcher(new Container()); $capsule->setEventDispatcher($dispatcher); $capsule->setAsGlobal(); $capsule->bootEloquent(); return $capsule; } /** * Get the connection query log. * * @param string $connectionName * @return array */ public function getQueryLog($connectionName = null) { return $this->getConnection($connectionName)->getQueryLog(); } /** * Clear the query log. * * @param string $connectionName * @return void */ public function flushQueryLog($connectionName = null) { $this->getConnection($connectionName)->flushQueryLog(); } /** * Close PDO connection */ public function disconnect() { $this->manager->disconnect(); $this->_connection = null; } /** * Enable the query log on the connection. * * @return void */ public function enableQueryLog() { $this->manager->enableQueryLog(); } /** * Disable the query log on the connection. * * @return void */ public function disableQueryLog() { $this->manager->disableQueryLog(); } }