diff --git a/application/bundles.php b/application/bundles.php new file mode 100644 index 00000000..49d126bb --- /dev/null +++ b/application/bundles.php @@ -0,0 +1,36 @@ + array( +| 'location' => 'admin', +| 'handles' => 'admin', +| ), +| +| Note that the "location" is relative to the "bundles" directory. +| Now the bundle will be recognized by Laravel and will be able +| to respond to requests beginning with "admin"! +| +| Have a bundle that lives in the root of the bundle directory +| and doesn't respond to any requests? Just add the bundle +| name to the array and we'll take care of the rest. +| +*/ + +return array(); \ No newline at end of file diff --git a/application/config/application.php b/application/config/application.php index fe0f3472..d81b4221 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -97,35 +97,6 @@ 'timezone' => 'UTC', - /* - |-------------------------------------------------------------------------- - | Bundle Options - |-------------------------------------------------------------------------- - | - | Here you may specify options related to application bundles, such as the - | amount of time the bundle manifest is cached. Each option is detailed - | below with suggestions for sensible values. - | - | Cache: - | - | All bundles have a "bundle.info" file which contains information such - | as the name of a bundle and the URIs it responds to. This value is - | the number of minutes that bundle info is cached. - | - | Auto: - | - | You may wish to auto-start some bundles instead of lazy-loading them. - | This is useful for debug bundles as well as bundles that are used - | throughout your application. You may specify which bundles should - | be auto-loaded in this array. - | - */ - - 'bundle' => array( - 'cache' => 0, - 'auto' => array(), - ), - /* |-------------------------------------------------------------------------- | Class Aliases @@ -168,6 +139,7 @@ 'Redis' => 'Laravel\\Redis', 'Request' => 'Laravel\\Request', 'Response' => 'Laravel\\Response', + 'Route' => 'Laravel\\Routing\\Route', 'Router' => 'Laravel\\Routing\\Router', 'Schema' => 'Laravel\\Database\\Schema', 'Section' => 'Laravel\\Section', diff --git a/application/controllers/base.php b/application/controllers/base.php index 71d03416..177d887a 100644 --- a/application/controllers/base.php +++ b/application/controllers/base.php @@ -7,7 +7,7 @@ class Base_Controller extends Controller { * * @param string $method * @param array $parameters - * @return Laravel\Response + * @return Response */ public function __call($method, $parameters) { diff --git a/application/routes.php b/application/routes.php index 7bfd2439..464ceb29 100644 --- a/application/routes.php +++ b/application/routes.php @@ -12,32 +12,57 @@ | | Let's respond to a simple GET request to http://example.com/hello: | -| Router::register('GET /hello', function() +| Route::get('hello', function() | { | return 'Hello World!'; | }); | | You can even respond to more than one URI: | -| Router::register('GET /hello, GET /world', function() +| Route::post('hello, world', function() | { | return 'Hello World!'; | }); | | It's easy to allow URI wildcards using (:num) or (:any): | -| Router::register('GET /hello/(:any)', function($name) +| Route::put('hello/(:any)', function($name) | { | return "Welcome, $name."; | }); | */ -Router::register(array('GET /', 'GET /home'), function() +Route::get('/, home', function() { return View::make('home.index'); }); +/* +|-------------------------------------------------------------------------- +| Application 404 & 500 Error Handlers +|-------------------------------------------------------------------------- +| +| To centralize and simplify 404 handling, Laravel uses an awesome event +| system to retrieve the response. Feel free to modify this function to +| your tastes and the needs of your application. +| +| Similarly, we use an event to handle the display of 500 level errors +| within the application. These errors are fired when there is an +| uncaught exception thrown in the application. +| +*/ + +Event::listen('404', function() +{ + return Response::error('404'); +}); + +Event::listen('500', function() +{ + return Response::error('500'); +}); + /* |-------------------------------------------------------------------------- | Route Filters diff --git a/application/start.php b/application/start.php index 368531bc..d64bbd98 100644 --- a/application/start.php +++ b/application/start.php @@ -1,5 +1,24 @@ path('app').'controllers/base.php', +)); + /* |-------------------------------------------------------------------------- | Auto-Loader PSR-0 Directories @@ -18,24 +37,4 @@ Autoloader::psr(array( path('app').'models', path('app').'libraries', -)); - -/* -|-------------------------------------------------------------------------- -| Auto-Loader Mappings -|-------------------------------------------------------------------------- -| -| Laravel uses a simple array of class to path mappings to drive the class -| auto-loader. This simple approach helps avoid the performance problems -| of searching through directories by some kind of convention. It also -| gives you the freedom to organize your application how you want. -| -| Registering a mapping couldn't be easier. Just pass an array of class -| to path maps into the "map" function of Autoloader. Then, when you -| want to use that class, just use it. It's a piece of cake. -| -*/ - -Autoloader::map(array( - 'Base_Controller' => path('app').'controllers/base.php', )); \ No newline at end of file diff --git a/laravel/autoloader.php b/laravel/autoloader.php index f42e87f8..9b33d788 100644 --- a/laravel/autoloader.php +++ b/laravel/autoloader.php @@ -104,7 +104,7 @@ protected static function load_psr($class, $directory = null) { // The PSR-0 standard indicates that class namespaces and underscores // shoould be used to indcate the directory tree in which the class - // resides, so we'll convert them to directory slashes. + // resides, so we'll convert them to slashes. $file = str_replace(array('\\', '_'), '/', $class); $directories = $directory ?: static::$psr; diff --git a/laravel/bundle.php b/laravel/bundle.php index 14f1364b..6e683b43 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -33,103 +33,35 @@ class Bundle { public static $routed = array(); /** - * The cache key for the bundle manifest. + * Register the bundle for the application. * - * @var string - */ - const manifest = 'laravel.bundle.manifest'; - - /** - * Detect all of the installed bundles from disk. - * - * @param string $path - * @return array - */ - public static function detect($path) - { - return static::search($path); - } - - /** - * Detect all of the installed bundles from disk. - * - * @param string $path - * @return array - */ - protected static function search($path) - { - $bundles = array(); - - $items = new fIterator($path); - - foreach ($items as $item) - { - // If the item is a directory, we'll search for a bundle.info file. - // If one exists, we will add it to the bundle array. We will set - // the location automatically since we know it. - if ($item->isDir()) - { - $path = $item->getRealPath().DS.'bundle.php'; - - // If we found a file, we'll require in the array it contains - // and add it to the directory. The info array will contain - // basic info like the bundle name and any URIs it may - // handle incoming requests for. - if (file_exists($path)) - { - $info = require $path; - - $info['location'] = dirname($path).DS; - - $bundles[$info['name']] = $info; - - continue; - } - // If a bundle.info file doesn't exist within a directory, - // we'll recurse into the directory to keep searching in - // the bundle directory for nested bundles. - else - { - $recurse = static::detect($item->getRealPath()); - - $bundles = array_merge($bundles, $recurse); - } - } - } - - return $bundles; - } - - /** - * Register a bundle for the application. - * - * @param array $config + * @param string $bundle + * @param array $config * @return void */ - public static function register($config) + public static function register($bundle, $config = array()) { $defaults = array('handles' => null, 'auto' => false); - // If a handles clause has been specified, we will cap it with a trailing - // slash so the bundle is not extra greedy with its routes. Otherwise a - // bundle that handles "s" would handle all routes beginning with "s". - if (isset($config['handles'])) + // If the given configuration is actually a string, we will assume it is a + // location and set the bundle name to match it. This is common for most + // bundles who simply live in the root bundle directory. + if (is_string($config)) { - $config['handles'] = str_finish($config['handles'], '/'); + $bundle = $config; + + $config = array('location' => $bundle); } - static::$bundles[$config['name']] = array_merge($defaults, $config); - } + // IF no location is set, we will set the location to match the name of + // the bundle. This is for bundles who are installed to the root of + // the bundle directory so a location was not set. + if ( ! isset($config['location'])) + { + $config['location'] = $bundle; + } - /** - * Disable a bundle for the current request. - * - * @param string $bundle - * @return void - */ - public static function disable($bundle) - { - unset(static::$bundles[$bundle]); + static::$bundles[$bundle] = array_merge($defaults, $config); } /** @@ -151,8 +83,7 @@ public static function start($bundle) // Each bundle may have a "start" script which is responsible for preparing // the bundle for use by the application. The start script may register any - // classes the bundle uses with the auto-loader, or perhaps will start any - // dependent bundles so that they are available. + // classes the bundle uses with the auto-loader, etc. if (file_exists($path = static::path($bundle).'start'.EXT)) { require $path; @@ -178,6 +109,11 @@ public static function routes($bundle) { $path = static::path($bundle).'routes'.EXT; + // By setting the bundle property on the router the router knows what + // value to replace the (:bundle) place-holder with when the bundle + // routes are added, keeping the routes flexible. + Routing\Router::$bundle = static::option($bundle, 'handles'); + if ( ! static::routed($bundle) and file_exists($path)) { require $path; @@ -186,6 +122,17 @@ public static function routes($bundle) static::$routed[] = $bundle; } + /** + * Disable a bundle for the current request. + * + * @param string $bundle + * @return void + */ + public static function disable($bundle) + { + unset(static::$bundles[$bundle]); + } + /** * Determine which bundle handles the given URI. * @@ -200,7 +147,10 @@ public static function handles($uri) foreach (static::$bundles as $key => $value) { - if (starts_with($uri, $value['handles'])) return $key; + if (isset($value['handles']) and starts_with($uri, $value['handles'].'/')) + { + return $key; + } } return DEFAULT_BUNDLE; @@ -217,6 +167,19 @@ public static function exists($bundle) return $bundle == DEFAULT_BUNDLE or in_array(strtolower($bundle), static::names()); } + /** + * Get the full path location of a given bundle. + * + * @param string $bundle + * @return string + */ + public static function location($bundle) + { + $location = array_get(static::$bundles, $bundle.'.location'); + + return path('bundle').str_finish($location, DS); + } + /** * Determine if a given bundle has been started for the request. * @@ -277,7 +240,7 @@ public static function class_prefix($bundle) */ public static function path($bundle) { - return ($bundle == DEFAULT_BUNDLE) ? path('app') : static::$bundles[$bundle]['location']; + return ($bundle == DEFAULT_BUNDLE) ? path('app') : static::location($bundle); } /** @@ -401,7 +364,7 @@ public static function parse($identifier) * Get the information for a given bundle. * * @param string $bundle - * @return array + * @return object */ public static function get($bundle) { diff --git a/laravel/cache/drivers/apc.php b/laravel/cache/drivers/apc.php index b2a48d25..2852aee8 100644 --- a/laravel/cache/drivers/apc.php +++ b/laravel/cache/drivers/apc.php @@ -39,7 +39,7 @@ public function has($key) */ protected function retrieve($key) { - if ( ! is_null($cache = apc_fetch($this->key.$key))) + if (($cache = apc_fetch($this->key.$key)) !== false) { return $cache; } diff --git a/laravel/cli/artisan.php b/laravel/cli/artisan.php index ea6d8dd5..a838f8e0 100644 --- a/laravel/cli/artisan.php +++ b/laravel/cli/artisan.php @@ -10,26 +10,6 @@ */ Bundle::start(DEFAULT_BUNDLE); -/** - * Set the CLI options on the $_SERVER global array so we can easily - * retrieve them from the various parts of the CLI code. We can use - * the Request class to access them conveniently. - */ -list($arguments, $_SERVER['CLI']) = Command::options($_SERVER['argv']); - -$_SERVER['CLI'] = array_change_key_case($_SERVER['CLI'], CASE_UPPER); - -/** - * The Laravel environment may be specified on the CLI using the "env" - * option, allowing the developer to easily use local configuration - * files from the CLI since the environment is usually controlled - * by server environmenet variables. - */ -if (isset($_SERVER['CLI']['ENV'])) -{ - $_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV']; -} - /** * The default database connection may be set by specifying a value * for the "database" CLI option. This allows migrations to be run diff --git a/laravel/cli/tasks/bundle/bundler.php b/laravel/cli/tasks/bundle/bundler.php index 78913ce2..9743671b 100644 --- a/laravel/cli/tasks/bundle/bundler.php +++ b/laravel/cli/tasks/bundle/bundler.php @@ -55,10 +55,8 @@ public function install($bundles) $this->download($bundle, $path); - echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL; + echo "Bundle [{$bundle['name']}] installed!".PHP_EOL; } - - $this->refresh(); } /** @@ -83,7 +81,7 @@ public function upgrade($bundles) // First we want to retrieve the information for the bundle, such as // where it is currently installed. This will allow us to upgrade // the bundle into it's current installation path. - $bundle = Bundle::get($name); + $location = Bundle::location($name); // If the bundle exists, we will grab the data about the bundle from // the API so we can make the right bundle provider for the bundle, @@ -98,89 +96,12 @@ public function upgrade($bundles) // Once we have the bundle information from the API, we'll simply // recursively delete the bundle and then re-download it using // the correct provider assigned to the bundle. - File::rmdir($bundle['location']); + File::rmdir($location); - $this->download($response['bundle'], $bundle['location']); + $this->download($response['bundle'], $location); echo "Bundle [{$name}] has been upgraded!".PHP_EOL; } - - $this->refresh(); - } - - /** - * Publish bundle assets to the public directory. - * - * @param array $bundles - * @return void - */ - public function publish($bundles) - { - if (count($bundles) == 0) $bundles = Bundle::names(); - - array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'publish')); - } - - /** - * Create a new bundle stub. - * - * @param array $arguments - * @return void - */ - public function make($arguments) - { - if ( ! isset($arguments[0])) - { - throw new \Exception("We need to know the bundle name!"); - } - - // First we'll grab the name from the argument list and make sure a bundle - // with that name doesn't already exist. If it does, we'll bomb out and - // notify the developer of the problem. Bundle names must be unique - // since classes are prefixed with the name. - $options['name'] = $name = $arguments[0]; - - if (Bundle::exists($name)) - { - throw new \Exception("That bundle already exists!"); - } - - // The developer may specify a location to which the bundle should be - // installed. If a location is not specified, the bundle name will - // be used as the default installation location. - $location = Request::server('cli.location') ?: $name; - - $location = path('bundle').$location; - - $options['handles'] = Request::server('cli.handles'); - - // We'll create the actual PHP that should be inserted into the info - // file for the bundle. This contains the bundle's name as well as - // any URIs it is setup to handle. - $info = 'refresh(); - } - - /** - * Clear the bundle manifest cache. - * - * @return void - */ - public function refresh() - { - Cache::forget(Bundle::manifest); - - echo 'Bundle cache cleared!'.PHP_EOL; } /** @@ -197,7 +118,7 @@ protected function get($bundles) { // First we'll call the bundle repository to gather the bundle data // array, which contains all of the information needed to install - // the bundle into the application. + // the bundle into the Laravel application. $response = $this->retrieve($bundle); if ($response['status'] == 'not-found') @@ -207,12 +128,14 @@ protected function get($bundles) // If the bundle was retrieved successfully, we will add it to // our array of bundles, as well as merge all of the bundle's - // dependencies into the array of responses so that they are - // installed along with the consuming dependency. + // dependencies into the array of responses. $bundle = $response['bundle']; $responses[] = $bundle; + // We'll also get the bundle's declared dependenceis so they + // can be installed along with the bundle, making it easy + // to install a group of bundles. $dependencies = $this->get($bundle['dependencies']); $responses = array_merge($responses, $dependencies); @@ -221,6 +144,19 @@ protected function get($bundles) return $responses; } + /** + * Publish bundle assets to the public directory. + * + * @param array $bundles + * @return void + */ + public function publish($bundles) + { + if (count($bundles) == 0) $bundles = Bundle::names(); + + array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'publish')); + } + /** * Install a bundle using a provider. * diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 42f949ad..b7727f52 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -115,7 +115,7 @@ public function rollback($arguments = array()) // along with their bundles and names. We will iterate through each // migration and run the "down" method, removing them from the // database as we go. - foreach ($migrations as $migration) + foreach (array_reverse($migrations) as $migration) { $migration['migration']->down(); diff --git a/laravel/core.php b/laravel/core.php index 62484791..2c37c458 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -30,6 +30,40 @@ */ spl_autoload_register(array('Laravel\\Autoloader', 'load')); +/** + * Register the Laravel namespace so that the auto-loader loads it + * according to the PSR-0 naming conventions. This should provide + * fast resolution of all core classes. + */ +Autoloader::namespaces(array('Laravel' => path('sys'))); + +/** + * Set the CLI options on the $_SERVER global array so we can easily + * retrieve them from the various parts of the CLI code. We can use + * the Request class to access them conveniently. + */ +if (defined('STDIN')) +{ + $console = CLI\Command::options($_SERVER['argv']); + + list($arguments, $options) = $console; + + $options = array_change_key_case($options, CASE_UPPER); + + $_SERVER['CLI'] = $options; +} + +/** + * The Laravel environment may be specified on the CLI using the env + * option, allowing the developer to easily use local configuration + * files from the CLI since the environment is usually controlled + * by server environmenet variables. + */ +if (isset($_SERVER['CLI']['ENV'])) +{ + $_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV']; +} + /** * Register all of the core class aliases. These aliases provide a * convenient way of working with the Laravel core classes without @@ -38,35 +72,6 @@ */ Autoloader::$aliases = Config::get('application.aliases'); -/** - * Register the Laravel namespace so that the auto-loader loads it - * according to the PSR-0 naming conventions. This should provide - * fast resolution of all core classes. - */ -Autoloader::namespaces(array('Laravel' => path('sys'))); - -/** - * Grab the bundle manifest for the application. This contains an - * array of all of the installed bundles, plus information about - * each of them. If it's not cached, we'll detect them and then - * cache it to save time later. - */ -$bundles = Cache::remember(Bundle::manifest, function() -{ - return Bundle::detect(path('bundle')); - -}, Config::get('application.bundle.cache')); - -/** - * Register all of the bundles that are defined in the main bundle - * manifest. This informs the framework where the bundle lives - * and which URIs it can respnod to. - */ -foreach ($bundles as $bundle) -{ - Bundle::register($bundle); -} - /** * Register the default timezone for the application. This will * be the default timezone used by all date functions through @@ -74,4 +79,16 @@ */ $timezone = Config::get('application.timezone'); -date_default_timezone_set($timezone); \ No newline at end of file +date_default_timezone_set($timezone); + +/** + * Finally we'll grab all of the bundles and register them + * with the bundle class. All of the bundles are stored in + * an array within the application directory. + */ +$bundles = require path('app').'bundles'.EXT; + +foreach ($bundles as $bundle => $config) +{ + Bundle::register($bundle, $config); +} \ No newline at end of file diff --git a/laravel/database/connectors/mysql.php b/laravel/database/connectors/mysql.php index 16cbc2a7..78d35917 100644 --- a/laravel/database/connectors/mysql.php +++ b/laravel/database/connectors/mysql.php @@ -20,11 +20,11 @@ public function connect($config) // Check for any optional MySQL PDO options. These options are not required // to establish a PDO connection; however, may be needed in certain server // or hosting environments used by the developer. - foreach (array('port', 'unix_socket') as $key => $value) + foreach (array('port', 'unix_socket') as $key) { if (isset($config[$key])) { - $dsn .= ";{$key}={$value}"; + $dsn .= ";{$key}={$config[$key]}"; } } diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index 2927237e..375183dd 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -23,14 +23,14 @@ public function create(Table $table, Fluent $command) { $columns = implode(', ', $this->columns($table)); - // First we will generate the base table creation statement. Other than - // auto-incrementing keys, no indexes will be created during the first - // creation of the table. They will be added in separate commands. + // First we will generate the base table creation statement. Other than incrementing + // keys, no indexes will be created during the first creation of the table since + // they will be added in separate commands. $sql = 'CREATE TABLE '.$this->wrap($table).' ('.$columns.')'; - // MySQL supports various "engines" for database tables. If an engine - // was specified by the developer, we will set it after adding the - // columns the table creation statement. + // MySQL supports various "engines" for database tables. If an engine ws specified + // by the developer, we will set it after adding the columns the table creation + // statement. Some engines support extra indexes. if ( ! is_null($table->engine)) { $sql .= ' ENGINE = '.$table->engine; @@ -50,9 +50,9 @@ public function add(Table $table, Fluent $command) { $columns = $this->columns($table); - // Once we the array of column definitions, we need to add "add" - // to the front of each definition, then we'll concatenate the - // definitions using commas like normal and generate the SQL. + // Once we the array of column definitions, we need to add "add" to the front + // of each definition, then we'll concatenate the definitions using commas + // like normal and generate the SQL. $columns = implode(', ', array_map(function($column) { return 'ADD '.$column; @@ -77,7 +77,7 @@ protected function columns(Table $table) // Each of the data type's have their own definition creation method, // which is responsible for creating the SQL for the type. This lets // us to keep the syntax easy and fluent, while translating the - // types to the types used by the database. + // types to the correct types. $sql = $this->wrap($column).' '.$this->type($column); $elements = array('nullable', 'defaults', 'incrementer'); @@ -223,9 +223,9 @@ public function drop_column(Table $table, Fluent $command) { $columns = array_map(array($this, 'wrap'), $command->columns); - // Once we the array of column names, we need to add "drop" to the - // front of each column, then we'll concatenate the columns using - // commas and generate the alter statement SQL. + // Once we the array of column names, we need to add "drop" to the front + // of each column, then we'll concatenate the columns using commas and + // generate the alter statement SQL. $columns = implode(', ', array_map(function($column) { return 'DROP '.$column; diff --git a/laravel/database/schema/grammars/postgres.php b/laravel/database/schema/grammars/postgres.php index 1fb6d21a..ac34b282 100644 --- a/laravel/database/schema/grammars/postgres.php +++ b/laravel/database/schema/grammars/postgres.php @@ -16,9 +16,9 @@ public function create(Table $table, Fluent $command) { $columns = implode(', ', $this->columns($table)); - // First we will generate the base table creation statement. Other than - // auto-incrementing keys, no indexes will be created during the first - // creation of the table. They will be added in separate commands. + // First we will generate the base table creation statement. Other than incrementing + // keys, no indexes will be created during the first creation of the table since + // they will be added in separate commands. $sql = 'CREATE TABLE '.$this->wrap($table).' ('.$columns.')'; return $sql; @@ -35,9 +35,9 @@ public function add(Table $table, Fluent $command) { $columns = $this->columns($table); - // Once we the array of column definitions, we'll add "add column" - // to the front of each definition, then we'll concatenate the - // definitions using commas like normal and generate the SQL. + // Once we the array of column definitions, we need to add "add" to the front + // of each definition, then we'll concatenate the definitions using commas + // like normal and generate the SQL. $columns = implode(', ', array_map(function($column) { return 'ADD COLUMN '.$column; @@ -114,10 +114,9 @@ protected function defaults(Table $table, Fluent $column) */ protected function incrementer(Table $table, Fluent $column) { - // We don't actually need to specify an "auto_increment" keyword since - // we handle the auto-increment definition in the type definition for - // integers by changing the type to "serial", which is a convenient - // notational short-cut provided by Postgres. + // We don't actually need to specify an "auto_increment" keyword since we + // handle the auto-increment definition in the type definition for + // integers by changing the type to "serial". if ($column->type == 'integer' and $column->increment) { return ' PRIMARY KEY'; @@ -218,9 +217,9 @@ public function drop_column(Table $table, Fluent $command) { $columns = array_map(array($this, 'wrap'), $command->columns); - // Once we the array of column names, we need to add "drop" to the - // front of each column, then we'll concatenate the columns using - // commas and generate the alter statement SQL. + // Once we the array of column names, we need to add "drop" to the front + // of each column, then we'll concatenate the columns using commas and + // generate the alter statement SQL. $columns = implode(', ', array_map(function($column) { return 'DROP COLUMN '.$column; diff --git a/laravel/database/schema/grammars/sqlite.php b/laravel/database/schema/grammars/sqlite.php index b86b9fb2..f704cc1c 100644 --- a/laravel/database/schema/grammars/sqlite.php +++ b/laravel/database/schema/grammars/sqlite.php @@ -16,26 +16,22 @@ public function create(Table $table, Fluent $command) { $columns = implode(', ', $this->columns($table)); - // First we will generate the base table creation statement. Other than - // auto-incrementing keys, no indexes will be created during the first - // creation of the table. They will be added in separate commands. + // First we will generate the base table creation statement. Other than incrementing + // keys, no indexes will be created during the first creation of the table since + // they will be added in separate commands. $sql = 'CREATE TABLE '.$this->wrap($table).' ('.$columns; - // SQLite does not allow adding a primary key as a command apart from - // when the table is initially created, so we'll need to sniff out - // any primary keys here and add them to the table. - // - // Because of this, this class does not have the typical "primary" - // method as it would be pointless since the primary keys can't - // be set on anything but the table creation statement. + // SQLite does not allow adding a primary key as a command apart from the creation + // of the table, so we'll need to sniff out any primary keys here and add them to + // the table now during this command. $primary = array_first($table->commands, function($key, $value) { return $value->type == 'primary'; }); - // If we found primary key in the array of commands, we'll create - // the SQL for the key addition and append it to the SQL table - // creation statement for the schema table. + // If we found primary key in the array of commands, we'll create the SQL for + // the key addition and append it to the SQL table creation statement for + // the schema table so the index is properly generated. if ( ! is_null($primary)) { $columns = $this->columnize($primary->columns); @@ -57,18 +53,18 @@ public function add(Table $table, Fluent $command) { $columns = $this->columns($table); - // Once we have an array of all of the column definitions, we need to - // spin through each one and prepend "ADD COLUMN" to each of them, - // which is the syntax used by SQLite when adding columns. + // Once we the array of column definitions, we need to add "add" to the front + // of each definition, then we'll concatenate the definitions using commas + // like normal and generate the SQL. $columns = array_map(function($column) { return 'ADD COLUMN '.$column; }, $columns); - // SQLite only allows one column to be added in an ALTER statement, - // so we will create an array of statements and return them all to - // the schema manager, which will execute each one. + // SQLite only allows one column to be added in an ALTER statement, so we + // will create an array of statements and return them all to the schema + // manager, which will execute each one separately. foreach ($columns as $column) { $sql[] = 'ALTER TABLE '.$this->wrap($table).' '.$column; diff --git a/laravel/database/schema/grammars/sqlserver.php b/laravel/database/schema/grammars/sqlserver.php index b4b5342c..7b20fdd5 100644 --- a/laravel/database/schema/grammars/sqlserver.php +++ b/laravel/database/schema/grammars/sqlserver.php @@ -23,9 +23,9 @@ public function create(Table $table, Fluent $command) { $columns = implode(', ', $this->columns($table)); - // First we will generate the base table creation statement. Other than - // auto-incrementing keys, no indexes will be created during the first - // creation of the table. They will be added in separate commands. + // First we will generate the base table creation statement. Other than incrementing + // keys, no indexes will be created during the first creation of the table since + // they will be added in separate commands. $sql = 'CREATE TABLE '.$this->wrap($table).' ('.$columns.')'; return $sql; @@ -42,9 +42,9 @@ public function add(Table $table, Fluent $command) { $columns = $this->columns($table); - // Once we the array of column definitions, we need to add "add" - // to the front of each definition, then we'll concatenate the - // definitions using commas like normal and generate the SQL. + // Once we the array of column definitions, we need to add "add" to the front + // of each definition, then we'll concatenate the definitions using commas + // like normal and generate the SQL. $columns = implode(', ', array_map(function($column) { return 'ADD '.$column; @@ -166,18 +166,18 @@ public function fulltext(Table $table, Fluent $command) { $columns = $this->columnize($command->columns); - // SQL Server requires the creation of a full-text "catalog" before - // creating a full-text index, so we'll first create the catalog - // then add another statement for the index. The catalog will - // be updated automatically by the server. + $table = $this->wrap($table); + + // SQL Server requires the creation of a full-text "catalog" before creating + // a full-text index, so we'll first create the catalog then add another + // separate statement for the index. $sql[] = "CREATE FULLTEXT CATALOG {$command->catalog}"; - $create = "CREATE FULLTEXT INDEX ON ".$this->wrap($table)." ({$columns}) "; + $create = "CREATE FULLTEXT INDEX ON ".$table." ({$columns}) "; - // Full-text indexes must specify a unique, non-nullable column as - // the index "key" and this should have been created manually by - // the developer in a separate column addition command, so we - // can just specify it in this statement. + // Full-text indexes must specify a unique, non-null column as the index + // "key" and this should have been created manually by the developer in + // a separate column addition command. $sql[] = $create .= "KEY INDEX {$command->key} ON {$command->catalog}"; return $sql; @@ -235,9 +235,9 @@ public function drop_column(Table $table, Fluent $command) { $columns = array_map(array($this, 'wrap'), $command->columns); - // Once we the array of column names, we need to add "drop" to the - // front of each column, then we'll concatenate the columns using - // commas and generate the alter statement SQL. + // Once we the array of column names, we need to add "drop" to the front + // of each column, then we'll concatenate the columns using commas and + // generate the alter statement SQL. $columns = implode(', ', array_map(function($column) { return 'DROP '.$column; diff --git a/laravel/error.php b/laravel/error.php index 15bebd98..edcb7ad3 100644 --- a/laravel/error.php +++ b/laravel/error.php @@ -25,9 +25,15 @@ public static function exception($exception)
".$exception->getTraceAsString()."