From ec84d3f90d924e5b538d942f70c5ed6554cec95f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 20 Feb 2012 14:00:11 -0600 Subject: [PATCH] added ability to specify autoloader configuration for bundles in bundles.php --- laravel/bundle.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/laravel/bundle.php b/laravel/bundle.php index 4a6f74f7..b9bbfd51 100644 --- a/laravel/bundle.php +++ b/laravel/bundle.php @@ -63,6 +63,8 @@ public static function register($bundle, $config = array()) } static::$bundles[$bundle] = array_merge($defaults, $config); + + static::autoloading($bundle, $config); } /** @@ -125,6 +127,35 @@ public static function routes($bundle) } } + /** + * Register the auto-loading configuration for a bundle. + * + * @param string $bundle + * @param array $config + * @return void + */ + protected static function autoloading($bundle, $config) + { + $path = trim(Bundle::path($bundle), DS); + + foreach ((array) $config['autoloads'] as $type => $mappings) + { + // When registering each type of mapping we'll replace the (:bundle) + // place-holder with the path to the bundle's root directory, so + // the developer may dryly register the mappings. + $mappings = array_map(function($mapping) use ($path) + { + return str_replace('(:bundle)', $path, $mapping); + + }, $mappings); + + // Once the mappings are formatted, we will call the Autoloader + // function matching the mapping type and pass in the array of + // mappings so they can be registered and used. + Autoloader::$type($mappings); + } + } + /** * Disable a bundle for the current request. *