1<?php
2/**
3 *
4 * @param string $className Class or Interface name automatically
5 * passed to this function by the PHP Interpreter
6 */
7function autoLoader($className){
8 //Directories added here must be relative to the script going to use this file
9 $directories = array(
10 '',
11 'classes/'
12 );
13
14 //Add your file naming formats here
15 $fileNameFormats = array(
16 '%s.php',
17 '%s.class.php',
18 'class.%s.php',
19 '%s.inc.php'
20 );
21
22 // this is to take care of the PEAR style of naming classes
23 $path = str_ireplace('_', '/', $className);
24 if(@include_once $path.'.php'){
25 return;
26 }
27
28 foreach($directories as $directory){
29 foreach($fileNameFormats as $fileNameFormat){
30 $path = $directory.sprintf($fileNameFormat, $className);
31 if(file_exists($path)){
32 include_once $path;
33 return;
34 }
35 }
36 }
37}
38
39spl_autoload_register('autoLoader');
40?>
41