Created
March 30, 2012 21:41
-
-
Save mbernson/2255403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Autoloader | |
*/ | |
// Define some useful constants | |
if(!defined('DS')) | |
define('DS', DIRECTORY_SEPARATOR); | |
if(!defined('PS')) | |
define('PS', PATH_SEPARATOR); | |
// Set up an array with the directories we'll use for inclusions | |
$directories = array_map(function($path) { | |
$path = str_replace('/', DS, $path); | |
return dirname(__FILE__).DS.$path; | |
}, | |
// We'll look in these directories for the classes | |
array( | |
'app/controller', | |
'app/model', | |
'app/view', | |
'app/plugins', | |
'app/lib' | |
)); | |
set_include_path( | |
get_include_path(). | |
PS. | |
implode(PS, $directories) | |
); | |
spl_autoload_register(function($classname) { | |
$classfile = $classname.'.php'; | |
if(file_exists($classfile)) | |
require_once $classfile; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment