Commit 56ae5e9a authored by Taylor Otwell's avatar Taylor Otwell

more autoloader tweaks.

parent 94b48870
...@@ -181,33 +181,42 @@ class Autoloader { ...@@ -181,33 +181,42 @@ class Autoloader {
} }
/** /**
* Map namespaces to directories. * Register underscored "namespaces" to directory mappings.
* *
* @param array $mappings * @param array $mappings
* @return void * @return void
*/ */
public static function namespaces($mappings) public static function underscored($mappings)
{
foreach ($mappings as $namespace => $directory)
{ {
$namespace = trim($namespace, '\\').'\\'; static::namespaces($mappings, '_');
static::$namespaces[$namespace] = head(static::format($directory));
}
} }
/** /**
* Register underscored "namespaces" to directory mappings. * Map namespaces to directories.
* *
* @param array $mappings * @param array $mappings
* @param string $append
* @return void * @return void
*/ */
public static function underscored($mappings) public static function namespaces($mappings, $append = '\\')
{ {
foreach ($mappings as $namespace => $directory) foreach ($mappings as $namespace => $directory)
{ {
static::$namespaces[$namespace.'_'] = head(static::format($directory)); // When adding new namespaces to the mappings, we will unset the previously
// mapped value if it existed. This allows previously registered spaces to
// be mapped to new directories on the fly.
$namespace = trim($namespace, $append).$append;
unset(static::$namespaces[$namespace]);
$namespaces[$namespace] = head(static::format($directory));
} }
// We'll array_merge the new mappings onto the front of the array so
// derivative namespaces are not always shadowed by their parents.
// For instance, when mappings Laravel\Docs, we don't want the
// main Laravel namespace to always override it.
static::$namespaces = array_merge($namespaces, static::$namespaces);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment