Commit 38541655 authored by Taylor Otwell's avatar Taylor Otwell

refactoring autoloader.

parent fe218f9b
......@@ -54,7 +54,7 @@ class Autoloader {
{
// After PHP namespaces were introduced, most libaries ditched underscores for
// for namespaces to indicate the class directory hierarchy. We will check for
// the present of namespace slashes to determine the directory separator.
// the presence of namespace slashes to determine the directory separator.
$separator = (strpos($class, '\\') !== false) ? '\\' : '_';
$library = substr($class, 0, strpos($class, $separator));
......@@ -66,12 +66,31 @@ class Autoloader {
// namespaces and underscores indicate the directory hierarchy of the class.
if (isset(static::$libraries[$library]))
{
return str_replace('_', '/', $file).EXT;
return LIBRARY_PATH.str_replace('_', '/', $file).EXT;
}
// Since not all controllers will be resolved by the controller resolver,
// we will do a quick check in the controller directory for the class.
// For instance, since base controllers would not be resolved by the
// controller class, we will need to resolve them here.
if (strpos($class, '_Controller') !== false)
{
$controller = str_replace(array('_Controller', '_'), array('', '/'), $class);
if (file_exists($path = strtolower(CONTROLLER_PATH.$controller.EXT)))
{
return $path;
}
}
// Next we will search through the common Laravel paths for the class file.
// The Laravel framework path, along with the libraries and models paths
// will be searched according to the Laravel class naming standard.
$lower = strtolower($file);
foreach (static::$paths as $path)
{
if (file_exists($path = $path.strtolower($file).EXT))
if (file_exists($path = $path.$lower.EXT))
{
return $path;
}
......@@ -86,20 +105,6 @@ class Autoloader {
return $path;
}
// Since not all controllers will be resolved by the controller resolver,
// we will do a quick check in the controller directory for the class.
// For instance, since base controllers would not be resolved by the
// controller class, we will need to resolve them here.
if (strpos($class, '_Controller') !== false)
{
$controller = str_replace(array('_Controller', '_'), array('', '/'), $class);
if (file_exists($path = strtolower(CONTROLLER_PATH.$controller.EXT)))
{
return $path;
}
}
}
}
\ No newline at end of file
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