shopengine
Last commit date
assets
11 months ago
base
11 months ago
compatibility
11 months ago
core
11 months ago
languages
11 months ago
libs
11 months ago
modules
11 months ago
traits
3 years ago
utils
11 months ago
widgets
11 months ago
woocommerce
11 months ago
autoloader.php
4 years ago
phpcs.xml
3 years ago
plugin.php
11 months ago
readme.txt
11 months ago
shopengine.php
11 months 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 |