Files
lgp-admin-plus-api/laravel/autoloader.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2011-10-31 22:15:47 -05:00
<?php namespace Laravel;
class Autoloader {
/**
* The PSR-0 compliant libraries registered with the auto-loader.
*
* @var array
*/
2011-10-31 23:00:13 -05:00
protected static $libraries = array();
2011-10-31 22:15:47 -05:00
/**
* The paths to be searched by the auto-loader.
*
* @var array
*/
2011-10-31 23:00:13 -05:00
protected static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
2011-10-31 22:15:47 -05:00
/**
* Load the file corresponding to a given class.
*
* @param string $class
* @return void
*/
2011-10-31 23:00:13 -05:00
public static function load($class)
2011-10-31 22:15:47 -05:00
{
2011-10-31 23:00:13 -05:00
// 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
// alias and bail out of the auto-load method.
if (array_key_exists($class, Config::$items['application']['aliases']))
2011-10-31 22:15:47 -05:00
{
2011-10-31 23:00:13 -05:00
return class_alias(Config::$items['application']['aliases'][$class], $class);
2011-10-31 22:15:47 -05:00
}
$file = str_replace('\\', '/', $class);
$namespace = substr($class, 0, strpos($class, '\\'));
2011-10-31 23:00:13 -05:00
// If the class namespace exists in the libraries array, it means that the
// 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, static::$libraries))
2011-10-31 22:15:47 -05:00
{
2011-10-31 23:00:13 -05:00
require LIBRARY_PATH.str_replace('_', '/', $file);
2011-10-31 22:15:47 -05:00
}
2011-10-31 23:00:13 -05:00
foreach (static::$paths as $path)
2011-10-31 22:15:47 -05:00
{
if (file_exists($path = $path.strtolower($file).EXT))
{
require $path;
return;
}
}
2011-10-31 23:00:13 -05:00
// If the namespace exists in the libraries directory, we will assume the
// library is PSR-0 compliant, and will add the namespace to the array of
// libraries and load the class accordingly.
if (is_dir(LIBRARY_PATH.$namespace))
2011-10-31 22:15:47 -05:00
{
2011-10-31 23:00:13 -05:00
static::$libraries[] = $namespace;
2011-10-31 22:15:47 -05:00
2011-10-31 23:00:13 -05:00
require LIBRARY_PATH.str_replace('_', '/', $file);
2011-10-31 22:15:47 -05:00
}
}
}