/** * Create a new session driver instance. * * @param string $driver * @return Session\Drivers\Driver */ public static function factory($driver) { if (isset(static::$registrar[$driver])) { $resolver = static::$registrar[$driver]; return $resolver(); } switch ($driver) { case 'apc': return new Session\Drivers\APC(Cache::driver('apc')); case 'cookie': return new Session\Drivers\Cookie(); case 'database': return new Session\Drivers\Database(Database::connection()); case 'file': return new Session\Drivers\File(path('storage') . 'sessions' . DS); case 'memcached': return new Session\Drivers\Memcached(Cache::driver('memcached')); case 'memory': return new Session\Drivers\Memory(); case 'redis': return new Session\Drivers\Redis(Cache::driver('redis')); default: throw new \Exception("Session driver [{$driver}] is not supported."); } }
/** * Add a performed SQL query to the Profiler. * * @param string $sql * @param array $bindings * @param float $time * @return void */ public static function query($sql, $bindings, $time) { foreach ($bindings as $binding) { $binding = Database::connection()->pdo->quote($binding); $sql = preg_replace('/\\?/', $binding, $sql, 1); } static::$data['queries'][] = array($sql, $time); }
/** * Execute the given schema operation against the database. * * @param Schema\Table $table * @return void */ public static function execute($table) { // The implications method is responsible for finding any fluently // defined indexes on the schema table and adding the explicit // commands that are needed to tbe schema instance. static::implications($table); foreach ($table->commands as $command) { $connection = DB::connection($table->connection); $grammar = static::grammar($connection); // Each grammar has a function that corresponds to the command type and // is for building that command's SQL. This lets the SQL syntax builds // stay granular across various database systems. if (method_exists($grammar, $method = $command->type)) { $statements = $grammar->{$method}($table, $command); // Once we have the statements, we will cast them to an array even // though not all of the commands return an array just in case it // needs multiple queries to complete. foreach ((array) $statements as $statement) { $connection->query($statement); } } } }
/** * Get the database connection for the Validator. * * @return Database\Connection */ protected function db() { if (!is_null($this->db)) { return $this->db; } return $this->db = Database::connection(); }
/** * Delete a model from the database. * * @param int $id * @return int */ public function delete($id = null) { // If the delete method is being called on an existing model, we only want to delete // that model. If it is being called from an Eloquent query model, it is probably // the developer's intention to delete more than one model, so we will pass the // delete statement to the query instance. if (!$this->exists) { return $this->query->delete(); } $table = static::table(get_class($this)); return DB::connection(static::$connection)->table($table)->delete($this->{static::$primary_key}); }
/** * Get the database connection for the model. * * @return Connection */ public function connection() { return Database::connection($this->model->connection()); }
/** * Get a query builder for the database table. * * @return Laravel\Database\Query */ protected function table() { $connection = DB::connection(Config::get('cache.database.connection')); return $connection->table(Config::get('cache.database.table')); }
/** * Get a database query instance for the migration table. * * @return Laravel\Database\Query */ protected function table() { return DB::connection(Request::server('cli.db'))->table('laravel_migrations'); }
/** * __construct * * @return void */ public function __construct() { $this->pdo = DB::connection()->pdo; $this->config = Config::get('database.connections.' . Config::get('database.default')); }