Commit fb984016 authored by Taylor Otwell's avatar Taylor Otwell

added loader class.

parent c70f0904
......@@ -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));
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;
System\Loader::bootstrap();
return;
}
}
});
spl_autoload_register(array('System\\Loader', 'load'));
// --------------------------------------------------------------
// Register the framework starting time with the Benchmarker.
......
<?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;
}
}
\ 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