advanced-access-manager
Last commit date
application
3 months ago
lang
1 year ago
media
5 months ago
vendor
11 months ago
aam.php
3 months ago
autoloader.php
1 year ago
index.php
1 year ago
license.txt
7 years ago
readme.txt
3 months ago
autoloader.php
101 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 auto-loader |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @version 7.0.0 |
| 15 | */ |
| 16 | class AAM_Autoloader |
| 17 | { |
| 18 | |
| 19 | /** |
| 20 | * PRS HTTP Message package |
| 21 | * |
| 22 | * @version 7.0.0 |
| 23 | */ |
| 24 | const PSRHM_BASEDIR = __DIR__ . '/vendor/psr-http-message'; |
| 25 | |
| 26 | /** |
| 27 | * Whip package |
| 28 | * |
| 29 | * @version 7.0.0 |
| 30 | */ |
| 31 | const WHIP_BASEDIR = __DIR__ . '/vendor/whip'; |
| 32 | |
| 33 | /** |
| 34 | * Class map |
| 35 | * |
| 36 | * @var array |
| 37 | * @access protected |
| 38 | * |
| 39 | * @version 7.0.7 |
| 40 | */ |
| 41 | protected static $class_map = []; |
| 42 | |
| 43 | /** |
| 44 | * Add new index |
| 45 | * |
| 46 | * @param string $class_name |
| 47 | * @param string $file_path |
| 48 | * @access public |
| 49 | * |
| 50 | * @version 7.0.0 |
| 51 | */ |
| 52 | public static function add($class_name, $file_path) |
| 53 | { |
| 54 | self::$class_map[$class_name] = $file_path; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Auto-loader for project Advanced Access Manager |
| 59 | * |
| 60 | * Try to load a class if prefix is AAM_ |
| 61 | * |
| 62 | * @param string $class_name |
| 63 | * |
| 64 | * @return void |
| 65 | * @access public |
| 66 | * |
| 67 | * @version 7.0.0 |
| 68 | */ |
| 69 | public static function load($class_name) |
| 70 | { |
| 71 | if (array_key_exists($class_name, self::$class_map)) { |
| 72 | $filename = self::$class_map[$class_name]; |
| 73 | } else { |
| 74 | $chunks = explode('_', $class_name); |
| 75 | $prefix = array_shift($chunks); |
| 76 | |
| 77 | if ($prefix === 'AAM') { |
| 78 | $base_path = __DIR__ . '/application'; |
| 79 | $filename = $base_path . '/' . implode('/', $chunks) . '.php'; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if (!empty($filename) && file_exists($filename)) { |
| 84 | require($filename); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Register auto-loader |
| 90 | * |
| 91 | * @return void |
| 92 | * @access public |
| 93 | * |
| 94 | * @version 7.0.0 |
| 95 | */ |
| 96 | public static function register() |
| 97 | { |
| 98 | spl_autoload_register('AAM_Autoloader::load'); |
| 99 | } |
| 100 | |
| 101 | } |