mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
added loader class.
This commit is contained in:
parent
c70f090465
commit
fb984016e8
@ -67,31 +67,16 @@ define('EXT', '.php');
|
||||
// --------------------------------------------------------------
|
||||
// Load the classes used by the auto-loader.
|
||||
// --------------------------------------------------------------
|
||||
require SYS_PATH.'loader'.EXT;
|
||||
require SYS_PATH.'config'.EXT;
|
||||
require SYS_PATH.'arr'.EXT;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Register the auto-loader.
|
||||
// --------------------------------------------------------------
|
||||
spl_autoload_register(function($class)
|
||||
{
|
||||
$file = strtolower(str_replace('\\', '/', $class));
|
||||
System\Loader::bootstrap();
|
||||
|
||||
if (array_key_exists($class, $aliases = System\Config::get('aliases')))
|
||||
{
|
||||
return class_alias($aliases[$class], $class);
|
||||
}
|
||||
|
||||
foreach (array(BASE_PATH, MODEL_PATH, LIBRARY_PATH) as $directory)
|
||||
{
|
||||
if (file_exists($path = $directory.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
spl_autoload_register(array('System\\Loader', 'load'));
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Register the framework starting time with the Benchmarker.
|
||||
|
71
system/loader.php
Normal file
71
system/loader.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php namespace System;
|
||||
|
||||
class Loader {
|
||||
|
||||
/**
|
||||
* The paths to be searched by the loader.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
|
||||
|
||||
/**
|
||||
* All of the class aliases.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $aliases = array();
|
||||
|
||||
/**
|
||||
* Bootstrap the auto-loader.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function bootstrap()
|
||||
{
|
||||
static::$aliases = require CONFIG_PATH.'aliases'.EXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class file for a given class name.
|
||||
*
|
||||
* This function is registered on the SPL auto-loader stack by the front controller during each request.
|
||||
*
|
||||
* All Laravel class names follow a namespace to directory convention. So, if a class exists in
|
||||
* application/libraries/user, it shouold be placed in the "User" namespace.
|
||||
*
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public static function load($class)
|
||||
{
|
||||
$file = strtolower(str_replace('\\', '/', $class));
|
||||
|
||||
if (array_key_exists($class, static::$aliases))
|
||||
{
|
||||
return class_alias(static::$aliases[$class], $class);
|
||||
}
|
||||
|
||||
foreach (static::$paths as $directory)
|
||||
{
|
||||
if (file_exists($path = $directory.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a path with the auto-loader.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public static function register($path)
|
||||
{
|
||||
static::$paths[] = $path;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user