Ejemplo n.º 1
0
 /**
  * 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.");
     }
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * Get the user from the database table.
  *
  * @param  array  $arguments
  * @return mixed
  */
 protected function get_user($arguments)
 {
     $table = Config::get('auth.table');
     return DB::table($table)->where(function ($query) use($arguments) {
         $username = Config::get('auth.username');
         $query->where($username, '=', $arguments['username']);
         foreach (array_except($arguments, array('username', 'password', 'remember')) as $column => $val) {
             $query->where($column, '=', $val);
         }
     })->first();
 }
Ejemplo n.º 4
0
 /**
  * Add / Update Data information
  *
  * @return void
  * @author 
  **/
 public static function setData($input)
 {
     $Category = $input['id'] == NULL || !isset($input['id']) ? new Content() : Content::find($input['id']);
     $tableCol = DB::query('show columns from ' . Content::$table);
     foreach ($tableCol as $value) {
         $fieldname = $value->field;
         if (stristr($value->field, 'name')) {
             $Category->{$fieldname} = $input['data'];
         } elseif (stristr($value->field, 'desc')) {
             $Category->{$fieldname} = $input['description'];
         }
     }
     $Category->save();
     $action = $input['id'] == NULL || !isset($input['id']) ? 'Insert' : '<b>(' . $input['id'] . ')</b> Update';
     Log::write('Data', 'Data <b>' . $input['data'] . '</b> ' . $action . ' by ' . Auth::user()->username);
 }
Ejemplo n.º 5
0
 /**
  * Seed the database from the given path.
  *
  * @param array   $arguments
  * @return int
  */
 public function seed($arguments = array())
 {
     $total = 0;
     foreach ($this->globSeedFiles() as $file) {
         $records = $this->loadSeedFile($file);
         // We'll grab the table name here, which could either come from the array or
         // from the filename itself. Then, we will simply insert the records into
         // the databases.
         $table = $this->fetchTableName($records, $file);
         Database::table($table)->delete();
         Database::table($table)->insert($records);
         $total += $count = count($records);
         echo sprintf("Seeded: `%s` (%d rows)\n", $table, $count);
     }
     return $total;
 }
Ejemplo n.º 6
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Adjust the value of a column up or down by a given amount.
  *
  * @param  string  $column
  * @param  int     $amount
  * @param  string  $operator
  * @return int
  */
 protected function adjust($column, $amount, $operator)
 {
     $wrapped = $this->grammar->wrap($column);
     // To make the adjustment to the column, we'll wrap the expression in an
     // Expression instance, which forces the adjustment to be injected into
     // the query as a string instead of bound.
     $value = Database::raw($wrapped . $operator . $amount);
     return $this->update(array($column => $value));
 }
Ejemplo n.º 8
0
 /**
  * Get the user from the database table by username.
  *
  * @param  mixed  $value
  * @return mixed
  */
 protected function get_user($value)
 {
     $table = Config::get('auth.table');
     $username = Config::get('auth.username');
     return DB::table($table)->where($username, '=', $value)->first();
 }
Ejemplo n.º 9
0
 /**
  * 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});
 }
Ejemplo n.º 10
0
 /**
  * Get the database connection for the model.
  *
  * @return Connection
  */
 public function connection()
 {
     return Database::connection($this->model->connection());
 }
Ejemplo n.º 11
0
 /**
  * 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::escape($binding);
         $sql = preg_replace('/\\?/', $binding, $sql, 1);
         $sql = htmlspecialchars($sql);
     }
     static::$data['queries'][] = array($sql, $time);
 }
Ejemplo n.º 12
0
 /**
  * Check Existing table
  *
  * @return void
  * @author 
  **/
 public static function checkTable($table, $field)
 {
     $existTable = DB::query("show tables like '" . $table . "'");
     $tableCol = DB::query("show columns from " . $table . " like '" . $field . "'");
     return !empty($existTable) && !empty($tableCol) ? true : false;
 }
Ejemplo n.º 13
0
 /**
  * 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();
 }
Ejemplo n.º 14
0
 /**
  * Drop the pre-migration schema for the current migration.
  *
  * @return void
  */
 protected function delete_schema()
 {
     DB::table('laravel_schema')->where('name', '=', get_class($this))->delete();
 }
Ejemplo n.º 15
0
 /**
  * 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');
 }
Ejemplo n.º 16
0
 /**
  * Gets the users' ids from which the current user has unread messages from
  * @return int[] Array with the users' IDs
  */
 public static function getUnreadUsers()
 {
     $myId = \Auth::user()->id;
     // Get all unread messages directed to me
     $messages = DB::table('messages')->where('status', '=', 'false')->where(function ($query) use($myId) {
         $query->or_where('to', '=', $myId);
     })->get();
     $users = array();
     foreach ($messages as $message) {
         $users[] = $message->from;
         // $users['nick'] = $message->nick;
     }
     return array_unique($users);
 }
Ejemplo n.º 17
0
 public function find($id)
 {
     $column = 'id';
     if (!is_numeric($id)) {
         if (is_null($this->slug)) {
             $this->code = 404;
             $this->data = 'You are trying to retrieve data with a slug from a resource that is not retrievable via a slug';
             return false;
         }
         if ($this->multilanguage) {
             $language_row = DB::table($this->language_table)->where_slug($id)->first(array($this->language_table_foreign_key, 'language_id'));
             if (is_null($language_row)) {
                 $id = null;
             } else {
                 $id = $language_row->{$this->language_table_foreign_key};
                 $this->options(array('filter' => array('language_id' => $language_row->language_id)));
             }
         } else {
             $column = 'slug';
         }
     } elseif ($this->parent && $this->parent->multilanguage) {
         if (!$this->input['language_id']) {
             $this->code = 404;
             $this->data = 'Please provide the language_id';
             return false;
         }
         $this->language_id = $this->input['language_id'];
         $this->model = $this->model->where($this->table . '.language_id', '=', $this->input['language_id']);
         $column = $this->parent->language_table_foreign_key;
     }
     $this->id = $id;
     $this->model = $this->model->where($this->table . '.' . $column, '=', $id);
     if (is_null($this->model->first())) {
         $this->code = 404;
         $this->data = 'The data you are trying to retrieve could not be found';
         return false;
     }
     return true;
 }
Ejemplo n.º 18
0
 /**
  * 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'));
 }
Ejemplo n.º 19
0
 /**
  * __construct
  *
  * @return void
  */
 public function __construct()
 {
     $this->pdo = DB::connection()->pdo;
     $this->config = Config::get('database.connections.' . Config::get('database.default'));
 }