refactoring the auto loader.
This commit is contained in:
parent
d44c076ebf
commit
a0bbc9d472
|
@ -7,14 +7,14 @@ class Autoloader {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $libraries = array();
|
protected $libraries = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The paths to be searched by the auto-loader.
|
* The paths to be searched by the auto-loader.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
|
protected $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the file corresponding to a given class.
|
* Load the file corresponding to a given class.
|
||||||
|
@ -22,7 +22,7 @@ class Autoloader {
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function load($class)
|
public function load($class)
|
||||||
{
|
{
|
||||||
// Most of the core classes are aliases for convenient access in spite of
|
// 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
|
// the namespace. If an alias is defined for the class, we will load the
|
||||||
|
@ -32,6 +32,22 @@ public static function load($class)
|
||||||
return class_alias(Config::$items['application']['aliases'][$class], $class);
|
return class_alias(Config::$items['application']['aliases'][$class], $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! is_null($path = $this->find($class)))
|
||||||
|
{
|
||||||
|
require $path;
|
||||||
|
|
||||||
|
$this->mappings[$class] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the file associated with a given class name.
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function find($class)
|
||||||
|
{
|
||||||
$file = str_replace('\\', '/', $class);
|
$file = str_replace('\\', '/', $class);
|
||||||
|
|
||||||
$namespace = substr($class, 0, strpos($class, '\\'));
|
$namespace = substr($class, 0, strpos($class, '\\'));
|
||||||
|
@ -40,18 +56,16 @@ public static function load($class)
|
||||||
// library is PSR-0 compliant, and we will load it following those standards.
|
// 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
|
// This allows us to add many third-party libraries to an application and be
|
||||||
// able to auto-load them automatically.
|
// able to auto-load them automatically.
|
||||||
if (array_key_exists($namespace, static::$libraries))
|
if (array_key_exists($namespace, $this->libraries))
|
||||||
{
|
{
|
||||||
require LIBRARY_PATH.str_replace('_', '/', $file);
|
return LIBRARY_PATH.str_replace('_', '/', $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (static::$paths as $path)
|
foreach ($this->paths as $path)
|
||||||
{
|
{
|
||||||
if (file_exists($path = $path.strtolower($file).EXT))
|
if (file_exists($path = $path.strtolower($file).EXT))
|
||||||
{
|
{
|
||||||
require $path;
|
return $path;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +74,9 @@ public static function load($class)
|
||||||
// libraries and load the class accordingly.
|
// libraries and load the class accordingly.
|
||||||
if (is_dir(LIBRARY_PATH.$namespace))
|
if (is_dir(LIBRARY_PATH.$namespace))
|
||||||
{
|
{
|
||||||
static::$libraries[] = $namespace;
|
$this->libraries[] = $namespace;
|
||||||
|
|
||||||
require LIBRARY_PATH.str_replace('_', '/', $file);
|
return LIBRARY_PATH.str_replace('_', '/', $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
|
|
||||||
IoC::bootstrap();
|
IoC::bootstrap();
|
||||||
|
|
||||||
spl_autoload_register(array('Laravel\\Autoloader', 'load'));
|
$loader = new Autoloader;
|
||||||
|
|
||||||
|
spl_autoload_register(array($loader, 'load'));
|
||||||
|
|
||||||
function e($value)
|
function e($value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?php namespace Laravel\Cache; use Laravel\IoC;
|
<?php namespace Laravel\Cache; use Laravel\IoC, Laravel\Config;
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class Manager {
|
||||||
*/
|
*/
|
||||||
public static function driver($driver = null)
|
public static function driver($driver = null)
|
||||||
{
|
{
|
||||||
if (is_null($driver)) $driver = Config::get('cache.default');
|
if (is_null($driver)) $driver = Config::get('cache.driver');
|
||||||
|
|
||||||
if ( ! array_key_exists($driver, static::$drivers))
|
if ( ! array_key_exists($driver, static::$drivers))
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
*
|
|
@ -0,0 +1 @@
|
||||||
|
*
|
Loading…
Reference in New Issue