Commit b262e743 by Taylor Otwell

autoload bundles based on namespace.

parent 106b5dc1
......@@ -67,6 +67,21 @@ class Autoloader {
return static::load_psr($class, $info['directory']);
}
// If the class is namespaced and a bundle exists that is assigned
// a name matching that namespace, we'll start the bundle and let
// the class fall through the method again.
if ( ! is_null($namespace = root_namespace($class)))
{
$namespace = strtolower($namespace);
if (Bundle::exists($namespace) and ! Bundle::started($namespace))
{
Bundle::start($namespace);
return static::load($class);
}
}
// If the class is not maped and is not part of a bundle or a mapped
// namespace, we'll make a last ditch effort to load the class via
// the PSR-0 from one of the registered directories.
......
......@@ -362,6 +362,20 @@ function str_finish($value, $cap)
}
/**
* Get the root namespace of a given class.
*
* @param string $class
* @return string
*/
function root_namespace($class)
{
if (str_contains($class, '\\'))
{
return head(explode('\\', $class));
}
}
/**
* Return the value of the given item.
*
* If the given item is a Closure the result of the Closure will be returned.
......
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