loader.php 1.63 KB
Newer Older
1 2 3 4 5 6
<?php

/**
 * This function is registered on the auto-loader stack by the front controller.
 */
return function($class) {
7

8 9 10
	// ----------------------------------------------------------
	// Replace namespace slashes with directory slashes.
	// ----------------------------------------------------------
11
	$file = strtolower(str_replace('\\', '/', $class));
12 13 14 15

	// ----------------------------------------------------------
	// Should the class be aliased?
	// ----------------------------------------------------------
16
	if (array_key_exists($class, $aliases = System\Config::get('aliases')))
17 18 19 20
	{
		return class_alias($aliases[$class], $class);
	}

21 22 23
	// ----------------------------------------------------------
	// Is the class a Laravel framework class?
	// ----------------------------------------------------------
24 25 26 27
	if (file_exists($path = BASE_PATH.$file.EXT))
	{
		require $path;
	}
28 29 30
	// ----------------------------------------------------------
	// Is the class in the application/models directory?
	// ----------------------------------------------------------
31 32 33 34
	elseif (file_exists($path = APP_PATH.'models/'.$file.EXT))
	{
		require $path;
	}
35
	// ----------------------------------------------------------
36
	// Is the class in the application/libraries directory?
37
	// ----------------------------------------------------------
38
	elseif (file_exists($path = APP_PATH.'libraries/'.$file.EXT))
39 40 41
	{
		require $path;
	}
42 43 44
	// ----------------------------------------------------------
	// Is the class anywhere in the application directory?
	// ----------------------------------------------------------
45 46 47 48 49 50
	elseif (file_exists($path = APP_PATH.$file.EXT))
	{
		require $path;
	}

};