autoloader.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * autoloader |
| 5 | * |
| 6 | * currently all classes of real objects (e.g. ads) can be found in /classes on the plugins root directory |
| 7 | * all classes have the "Advads_" prefix to prevent any conflicts with other plugins |
| 8 | * but filenames don’t use "advads" and are written in lower case |
| 9 | * e.g. Advads_Ad is in file classes/ad.php |
| 10 | * |
| 11 | * to be able to change this structure later, I use an autoloader here |
| 12 | */ |
| 13 | class Advads_Autoloader { |
| 14 | |
| 15 | public static function load($classname) { |
| 16 | // to lower case |
| 17 | $classname = strtolower($classname); |
| 18 | |
| 19 | // strip "advads_" prefix |
| 20 | $classname = str_replace('advads_', '', $classname); |
| 21 | |
| 22 | $filepath = ADVADS_BASE_PATH . 'classes' . DIRECTORY_SEPARATOR . $classname . '.php'; |
| 23 | |
| 24 | if (file_exists($filepath)) { |
| 25 | require_once $filepath; |
| 26 | } else { |
| 27 | return false; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | } |
| 32 |