From a92ab1ca308924a918b38a702057d56e1a8cdc5b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 20 Apr 2012 11:35:47 -0500 Subject: [PATCH] Fixing bugs. --- laravel/cache/drivers/driver.php | 16 ++++++++++++++-- laravel/cli/artisan.php | 15 +++------------ laravel/core.php | 10 +--------- laravel/database/schema.php | 5 ++++- laravel/helpers.php | 20 ++++++++++++++++++++ 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/laravel/cache/drivers/driver.php b/laravel/cache/drivers/driver.php index b74ebe0a..b4701eb8 100644 --- a/laravel/cache/drivers/driver.php +++ b/laravel/cache/drivers/driver.php @@ -69,15 +69,27 @@ abstract class Driver { * @param int $minutes * @return mixed */ - public function remember($key, $default, $minutes) + public function remember($key, $default, $minutes, $function = 'put') { if ( ! is_null($item = $this->get($key, null))) return $item; - $this->put($key, $default = value($default), $minutes); + $this->$function($key, $default = value($default), $minutes); return $default; } + /** + * Get an item from the cache, or cache the default value forever. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function sear($key, $default) + { + return $this->remember($key, $default, null, 'forever'); + } + /** * Delete an item from the cache. * diff --git a/laravel/cli/artisan.php b/laravel/cli/artisan.php index 44bb39ab..46886dc8 100644 --- a/laravel/cli/artisan.php +++ b/laravel/cli/artisan.php @@ -16,21 +16,12 @@ Bundle::start(DEFAULT_BUNDLE); * for the "database" CLI option. This allows migrations to be run * conveniently for a test or staging database. */ -if (isset($_SERVER['CLI']['DB'])) + +if ( ! is_null($database = get_cli_option('db'))) { - Config::set('database.default', $_SERVER['CLI']['DB']); + Config::set('database.default', $database); } -/** - * Overwrite the HttpFoundation request since we have set some of - * the server variables since it was created. This allows us to - * set the default database for the CLI task. - */ - -use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation; - -Request::$foundation = RequestFoundation::createFromGlobals(); - /** * We will register all of the Laravel provided tasks inside the IoC * container so they can be resolved by the task class. This allows diff --git a/laravel/core.php b/laravel/core.php index 94a36671..abcd809f 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -156,15 +156,7 @@ Request::$foundation = RequestFoundation::createFromGlobals(); if (Request::cli()) { - foreach (Request::foundation()->server->get('argv') as $argument) - { - if (starts_with($argument, '--env=')) - { - $environment = substr($argument, 6); - - break; - } - } + $environment = get_cli_option('env'); } else { diff --git a/laravel/database/schema.php b/laravel/database/schema.php index 3787e33b..bbc4bb01 100644 --- a/laravel/database/schema.php +++ b/laravel/database/schema.php @@ -44,12 +44,15 @@ class Schema { * Drop a database table from the schema. * * @param string $table + * @param string $connection * @return void */ - public static function drop($table) + public static function drop($table, $connection = null) { $table = new Schema\Table($table); + $table->on($connection); + // To indicate that the table needs to be dropped, we will run the // "drop" command on the table instance and pass the instance to // the execute method as calling a Closure isn't needed. diff --git a/laravel/helpers.php b/laravel/helpers.php index ae99959e..638d967c 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -504,4 +504,24 @@ function render_each($partial, array $data, $iterator, $empty = 'raw|') function yield($section) { return Laravel\Section::yield($section); +} + +/** + * Get a CLI option from the argv $_SERVER variable. + * + * @param string $option + * @param mixed $default + * @return string + */ +function get_cli_option($option, $default = null) +{ + foreach (Laravel\Request::foundation()->server->get('argv') as $argument) + { + if (starts_with($argument, "--{$option}=")) + { + return substr($argument, strlen($option) + 3); + } + } + + return value($default); } \ No newline at end of file