Prepare the database connection instance.

@param  \EApp\Database\Connection $connection
@param  string  $type
@return \EApp\Database\Connection
189972
protected function configure(Connection $connection, $type)
	{
		$connection = $this->setPdoForType($connection, $type);

		// First we'll set the fetch mode and a few other dependencies of the database
		// connection. This method basically just configures and prepares it to get
		// used by the application. Once we're finished we'll return it back out.
		if ($this->prop->getIs('events'))
		{
			$connection->setEventDispatcher($this->prop['events']);
		}

		// Here we'll set a reconnector callback. This reconnector can be any callable
		// so we will set a Closure to reconnect from this manager with the name of
		// the connection, which will allow us to reconnect from the connections.
		$connection->setReconnector(function ($connection) {
			$this->reconnect($connection->getName());
		});

		return $connection;
	}
624291
protected function prepare(Connection $connection)
	{
		$connection->setFetchMode($this->app['config']['database.fetch']);

		if ($this->app->bound('events'))
		{
			$connection->setEventDispatcher($this->app['events']);
		}

		// The database connection can also utilize a cache manager instance when cache
		// functionality is used on queries, which provides an expressive interface
		// to caching both fluent queries and FlyORM queries that are executed.
		$app = $this->app;

		$connection->setCacheManager(function() use ($app)
		{
			return $app['cache'];
		});

		// We will setup a Closure to resolve the paginator instance on the connection
		// since the Paginator isn't sued on every request and needs quite a few of
		// our dependencies. It'll be more efficient to lazily resolve instances.
		$connection->setPaginator(function() use ($app)
		{
			return $app['paginator'];
		});

		return $connection;
	}
553276
public function newFromBuilder($attributes = array(), $connection = null) {
    $typeField = static::$singleTableTypeField;
    $attributes = (array) $attributes;

    $classType = array_key_exists($typeField, $attributes) ? $attributes[$typeField] : null;

    if ($classType !== null) {
      $childTypes = static::getSingleTableTypeMap();
      if (array_key_exists($classType, $childTypes)) {
        $class = $childTypes[$classType];
        $instance = (new $class)->newInstance([], true);
        $instance->setFilteredAttributes($attributes);
        $instance->setConnection($connection ?: $this->getConnectionName());
        $instance->fireModelEvent('retrieved', false);
        return $instance;
      } else {
        // Something has gone very wrong with the Global Scope
        // There is not graceful recovery so complain loudly.
        throw new SingleTableInheritanceException("Cannot construct newFromBuilder for unrecognized $typeField=$classType");
      }
    } else {
      // There are some cases, like Model::pluck('id'), where $attributes does not contain classType
      // In those situations defer to the original implementation.
      return parent::newFromBuilder($attributes, $connection);
    }
  }
473214
protected static function useCustomGrammar($connection)
    {
        // just for MySqlGrammar
        if (get_class($connection) === 'Illuminate\Database\MySqlConnection') {
            $MySqlGrammar = $connection->withTablePrefix(new MySqlGrammar);
            $connection->setSchemaGrammar($MySqlGrammar);
        }

        return $connection->getSchemaBuilder();
    }
1306659
public function connection($connection = null)
    {
        $type = $connection ?? $this->defaultConnection;

        if (!isset($this->connection[$type]))
        {
            $slice = $this->slice->getSlice($type);

            $key     = $slice->getRequired('adapter');
            $adapter = $this->adapters[$key];

            $this->adapterProviders[$type] = new $adapter();

            $this->adapterProviders[$type]->setHost($slice->getData('host'));
            $this->adapterProviders[$type]->setPort($slice->getData('port'));

            if (method_exists($this->adapterProviders[$type], 'setPath'))
            {
                $this->adapterProviders[$type]->setPath($slice->getData('path'));
            }

            $this->adapterProviders[$type]->setDbName($slice->getData('database'));

            $this->adapterProviders[$type]->setConnection($this);

            $this->adapterProviders[$type]->setPDOClass(Connection::class);

            $options = [
                Connection::ATTR_DEFAULT_FETCH_MODE => Connection::FETCH_ASSOC,
                //Connection::ATTR_EMULATE_PREPARES   => true,
                //Connection::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                //Connection::ATTR_PERSISTENT         => false,
                //Connection::MYSQL_ATTR_INIT_COMMAND       => 'SET NAMES utf8mb4'
            ];

            if ($this->adapterProviders[$type]->name() !== 'sqlite')
            {
                $options[Connection::ATTR_ERRMODE] = Connection::ERRMODE_EXCEPTION;
            }

            $this->connection[$type] = $this->adapterProviders[$type]->connection(
                $slice->getData('username'),
                $slice->getData('password'),
                $slice->getData('options', $options)
            );
        }

        return $this->connection[$type];
    }
231892
public function make(Connection $connection, $name = null)
    {
        if ($name && $this->config->has('migrations.' . $name)) {
            $config = new Repository($this->config->get('migrations.' . $name, []));
        } else {
            $config = new Repository($this->config->get('migrations.default', []));
        }

        $configuration = new Configuration($connection);
        $configuration->setName($config->get('name', 'Doctrine Migrations'));
        $configuration->setMigrationsNamespace($config->get('namespace', 'Database\\Migrations'));
        $configuration->setMigrationsTableName($config->get('table', 'migrations'));

        $configuration->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression(
            $config->get('schema.filter', '/^(?).*$/')
        );

        $configuration->setNamingStrategy($this->container->make(
            $config->get('naming_strategy', DefaultNamingStrategy::class)
        ));

        $configuration->setMigrationsFinder($configuration->getNamingStrategy()->getFinder());

        $directory = $config->get('directory', database_path('migrations'));
        $configuration->setMigrationsDirectory($directory);
        $configuration->registerMigrationsFromDirectory($directory);

        return $configuration;
    }
1238258
public static function table( $table, $connection = null )
	{
		return self::getInstance()->getConnection($connection)->table($table);
	}
186605
protected function loadSession(Connection $connection)
    {
        $sessionId = $connection->session = $this->getSessionIdFromCookie($connection);
        
        $session = clone $this->Session;
        $session->setId($sessionId);
        $session->start();
        
        $readonly = (new ReadOnly(config('session.cookie')))->initialize($session->all(), $sessionId);
        WsSession::swap($readonly);
        Session::flush();
        
        unset($session);
    }
984209
public function from($connection)
    {
        if (!isset($this->settings[$connection])) {
            throw new InvalidArgumentException("Connection \"$connection\" is not configured.");
        }

        $settings = $this->settings[$connection];

        return new Twilio($settings['sid'], $settings['token'], $settings['from']);
    }
941740
protected static function getConnection($type) {
    $mapper = self::getMapper($type);
    $conn = $mapper->getConnection();
    return $conn;
  }
848671
public static function createFromConnection(Connection $connection)
    {
        $driver = $connection->getDriver()->getName();

        if ($driver === 'pdo_sqlite') {
            return new ConnectionHandler\SqliteConnectionHandler($connection);
        }

        if ($driver === 'pdo_pgsql') {
            return new ConnectionHandler\PostgresConnectionHandler($connection);
        }

        return new self($connection);
    }
1283630
protected function configure(Connection $connection, $name)
    {
        $connection->setName($name);

        if ($this->events && $this->app->bound('events')) {
            $connection->setEventDispatcher($this->app->make('events'));
        }

        return $connection;
    }
945010
protected function prepare(Connection $connection)
	{
		$connection->setFetchMode($this->app['config']['database.fetch']);

		if ($this->app->bound('events'))
		{
			$connection->setEventDispatcher($this->app['events']);
		}

		// Here we'll set a reconnector callback. This reconnector can be any callable
		// so we will set a Closure to reconnect from this manager with the name of
		// the connection, which will allow us to reconnect from the connections.
		$connection->setReconnector(function($connection)
		{
			$this->reconnect($connection->getName());
		});

		return $connection;
	}
1096109
public function getEventQueue(ConnectionInterface $connection)
    {
        if (!isset($this->queues[$connection])) {
            $this->queues[$connection] = new EventQueue;
        }
        return $this->queues[$connection];
    }
375940
protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
    {
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, [$connection, $database, $prefix, $config]);
        }

        switch ($driver) {
            case 'mysql':
                return new MySqlConnection($connection, $database, $prefix, $config);

            case 'pgsql':
                return new PostgresConnection($connection, $database, $prefix, $config);
        }

        return parent::createConnection($driver, $connection, $database, $prefix, $config);
    }
317038
protected function createConnection($connection)
    {
        // Load config connection
        $config = Arr::get($this->config, 'connections.' . $connection);
        if (is_null($config)) {
            throw new \InvalidArgumentException("config connection [$connection] not found.");
        }

        $driver = Arr::get($config, 'driver');
        if (is_null($driver)) {
            throw new \InvalidArgumentException("driver connection [$connection] not information.");
        }

        // We'll check to see if a creator method exists for the given connection. If not we
        // will check for a custom connection creator, which allows developers to create
        // connections using their own customized connection creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver, $config);
        } else {
            $method = 'create' . Str::studly($driver) . 'Driver';

            if (method_exists($this, $method)) {
                return $this->$method($config);
            }
        }
        throw new \InvalidArgumentException("driver [$driver] connection [$connection] not supported.");
    }
788487
public function setConnection(Connection $connection)
    {
        $this->connection = $connection;
        $this->prefix     = $this->connection->getConfig('prefix');

        return $this;
    }