refactoring the autoloader.
This commit is contained in:
parent
a0bbc9d472
commit
c0c8108399
|
@ -7,14 +7,14 @@ class Autoloader {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $libraries = array();
|
||||
protected static $libraries = array();
|
||||
|
||||
/**
|
||||
* The paths to be searched by the auto-loader.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
|
||||
protected static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
|
||||
|
||||
/**
|
||||
* Load the file corresponding to a given class.
|
||||
|
@ -22,7 +22,7 @@ class Autoloader {
|
|||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public function load($class)
|
||||
public static function load($class)
|
||||
{
|
||||
// Most of the core classes are aliases for convenient access in spite of
|
||||
// the namespace. If an alias is defined for the class, we will load the
|
||||
|
@ -32,11 +32,9 @@ public function load($class)
|
|||
return class_alias(Config::$items['application']['aliases'][$class], $class);
|
||||
}
|
||||
|
||||
if ( ! is_null($path = $this->find($class)))
|
||||
if ( ! is_null($path = static::find($class)))
|
||||
{
|
||||
require $path;
|
||||
|
||||
$this->mappings[$class] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +44,7 @@ public function load($class)
|
|||
* @param string $class
|
||||
* @return string
|
||||
*/
|
||||
protected function find($class)
|
||||
protected static function find($class)
|
||||
{
|
||||
$file = str_replace('\\', '/', $class);
|
||||
|
||||
|
@ -56,12 +54,12 @@ protected function find($class)
|
|||
// library is PSR-0 compliant, and we will load it following those standards.
|
||||
// This allows us to add many third-party libraries to an application and be
|
||||
// able to auto-load them automatically.
|
||||
if (array_key_exists($namespace, $this->libraries))
|
||||
if (array_key_exists($namespace, static::$libraries))
|
||||
{
|
||||
return LIBRARY_PATH.str_replace('_', '/', $file);
|
||||
}
|
||||
|
||||
foreach ($this->paths as $path)
|
||||
foreach (static::$paths as $path)
|
||||
{
|
||||
if (file_exists($path = $path.strtolower($file).EXT))
|
||||
{
|
||||
|
@ -74,7 +72,7 @@ protected function find($class)
|
|||
// libraries and load the class accordingly.
|
||||
if (is_dir(LIBRARY_PATH.$namespace))
|
||||
{
|
||||
$this->libraries[] = $namespace;
|
||||
static::$libraries[] = $namespace;
|
||||
|
||||
return LIBRARY_PATH.str_replace('_', '/', $file);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
$loader = new Autoloader;
|
||||
|
||||
spl_autoload_register(array($loader, 'load'));
|
||||
spl_autoload_register(array('Laravel\\Autoloader', 'load'));
|
||||
|
||||
function e($value)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue