Skip to content

Instantly share code, notes, and snippets.

@mbernson
Created March 30, 2012 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbernson/2255403 to your computer and use it in GitHub Desktop.
Save mbernson/2255403 to your computer and use it in GitHub Desktop.
<?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