From 70082508f51a0f80f85fd57d91801ecfecc50814 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 26 Jan 2012 20:07:02 -0600 Subject: [PATCH] improve bundle configuration and registration. --- application/routes.php | 1 + bundles/bundles.php | 4 ++++ laravel/bundle.php | 14 +++++++++++--- laravel/core.php | 6 ++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/application/routes.php b/application/routes.php index 7bfd2439..70075677 100644 --- a/application/routes.php +++ b/application/routes.php @@ -35,6 +35,7 @@ Router::register(array('GET /', 'GET /home'), function() { + var_dump(Bundle::$bundles); return View::make('home.index'); }); diff --git a/bundles/bundles.php b/bundles/bundles.php index 764b77d5..49d126bb 100644 --- a/bundles/bundles.php +++ b/bundles/bundles.php @@ -27,6 +27,10 @@ | 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/laravel/bundle.php b/laravel/bundle.php index 1cd58810..7ee967ff 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -35,14 +35,22 @@ public static function register($bundle, $config = array()) { $defaults = array('handles' => null, 'auto' => false); + // If the given config is actually a string, we will assume it is a location + // and convert it to an array so that the developer may conveniently add + // bundles to the configuration without making an array for each one. + if (is_string($config)) + { + $config = array('location' => $config); + } + if ( ! isset($config['location'])) { throw new \Exception("Location not set for bundle [$bundle]"); } - // We will trim the trailing slash from the location and add it back so we don't - // have to worry about the developer adding or not adding it to the location - // path for the bundle. This makes sure it is always there. + // We will trim the trailing slash from the location and add it back so + // we don't have to worry about the developer adding or not adding it + // to the location path for the bundle. $config['location'] = BUNDLE_PATH.rtrim($config['location'], DS).DS; static::$bundles[$bundle] = array_merge($defaults, $config); diff --git a/laravel/core.php b/laravel/core.php index 53defac3..652b6f22 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -47,7 +47,9 @@ */ $bundles = require BUNDLE_PATH.'bundles'.EXT; -foreach ($bundles as $bundle => $config) +foreach ($bundles as $bundle => $value) { - Bundle::register($bundle, $config); + if (is_numeric($bundle)) $bundle = $value; + + Bundle::register($bundle, $value); } \ No newline at end of file