advanced-access-manager
Last commit date
Application
7 years ago
Lang
7 years ago
media
7 years ago
vendor
7 years ago
aam.php
7 years ago
autoloader.php
7 years ago
license.txt
7 years ago
readme.txt
7 years ago
autoloader.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Project autoloader |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Autoloader { |
| 17 | |
| 18 | /** |
| 19 | * Class map |
| 20 | * |
| 21 | * @var array |
| 22 | * |
| 23 | * @access protected |
| 24 | * @static |
| 25 | */ |
| 26 | protected static $classmap = array(); |
| 27 | |
| 28 | /** |
| 29 | * Add new index |
| 30 | * |
| 31 | * @param string $classname |
| 32 | * @param string $filepath |
| 33 | * |
| 34 | * @access public |
| 35 | * @static |
| 36 | */ |
| 37 | public static function add($classname, $filepath) { |
| 38 | self::$classmap[$classname] = $filepath; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Autoloader for project Advanced Access Manager |
| 43 | * |
| 44 | * Try to load a class if prefix is AAM_ |
| 45 | * |
| 46 | * @param string $classname |
| 47 | */ |
| 48 | public static function load($classname) { |
| 49 | if (array_key_exists($classname, self::$classmap)) { |
| 50 | $filename = self::$classmap[$classname]; |
| 51 | } else { |
| 52 | $chunks = explode('_', $classname); |
| 53 | $prefix = array_shift($chunks); |
| 54 | |
| 55 | if ($prefix === 'AAM') { |
| 56 | $base_path = dirname(__FILE__) . '/Application'; |
| 57 | $filename = $base_path . '/' . implode('/', $chunks) . '.php'; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (!empty($filename) && file_exists($filename)) { |
| 62 | require($filename); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Register autoloader |
| 68 | * |
| 69 | * @return void |
| 70 | * |
| 71 | * @access public |
| 72 | */ |
| 73 | public static function register() { |
| 74 | spl_autoload_register('AAM_Autoloader::load'); |
| 75 | } |
| 76 | |
| 77 | } |