shopengine
Last commit date
assets
3 years ago
base
3 years ago
compatibility
3 years ago
core
3 years ago
languages
3 years ago
libs
3 years ago
modules
3 years ago
traits
3 years ago
utils
3 years ago
widgets
3 years ago
autoloader.php
3 years ago
phpcs.xml
3 years ago
plugin.php
3 years ago
readme.txt
3 years ago
shopengine.php
3 years ago
autoloader.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine; |
| 4 | |
| 5 | |
| 6 | defined('ABSPATH') || exit; |
| 7 | |
| 8 | /** |
| 9 | * ShopEngine autoloader. |
| 10 | * Handles dynamically loading classes only when needed. |
| 11 | * |
| 12 | * @since 1.0.0 |
| 13 | */ |
| 14 | class Autoloader |
| 15 | { |
| 16 | |
| 17 | /** |
| 18 | * Run autoloader. |
| 19 | * Register a function as `__autoload()` implementation. |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | * @access public |
| 23 | */ |
| 24 | public static function run() { |
| 25 | spl_autoload_register([__CLASS__, 'autoload']); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @param $class_name |
| 32 | */ |
| 33 | private static function autoload($class_name) { |
| 34 | |
| 35 | if(0 !== strpos($class_name, __NAMESPACE__)) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $file_name = strtolower( |
| 40 | preg_replace( |
| 41 | ['/\b' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/'], |
| 42 | ['', '$1-$2', '-', DIRECTORY_SEPARATOR], |
| 43 | $class_name |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | |
| 48 | $file = plugin_dir_path(__FILE__) . $file_name . '.php'; |
| 49 | |
| 50 | if(file_exists($file)) { |
| 51 | |
| 52 | require_once($file); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Calling the autoloader to class files |
| 60 | * |
| 61 | */ |
| 62 | Autoloader::run(); |
| 63 | |
| 64 | |
| 65 |