elementskit-lite
Last commit date
assets
2 weeks ago
compatibility
8 months ago
config
2 weeks ago
core
2 weeks ago
helpers
2 weeks ago
languages
2 weeks ago
libs
2 weeks ago
modules
2 weeks ago
traits
4 years ago
widgets
2 weeks ago
autoloader.php
4 years ago
elementskit-lite.php
2 weeks ago
plugin.php
2 weeks ago
readme.txt
2 weeks ago
wpml-config.xml
2 weeks ago
autoloader.php
59 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | /** |
| 7 | * ElementsKit_Lite autoloader. |
| 8 | * Handles dynamically loading classes only when needed. |
| 9 | * |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | class Autoloader { |
| 13 | |
| 14 | /** |
| 15 | * Run autoloader. |
| 16 | * Register a function as `__autoload()` implementation. |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | * @access public |
| 20 | */ |
| 21 | public static function run() { |
| 22 | spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Autoload. |
| 27 | * For a given class, check if it exist and load it. |
| 28 | * |
| 29 | * @since 1.0.0 |
| 30 | * @access private |
| 31 | * @param string $class Class name. |
| 32 | */ |
| 33 | private static function autoload( $class_name ) { |
| 34 | |
| 35 | // If the class being requested does not start with our prefix |
| 36 | // we know it's not one in our project. |
| 37 | if ( 0 !== strpos( $class_name, __NAMESPACE__ ) ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | $file_name = strtolower( |
| 42 | preg_replace( |
| 43 | array( '/\b' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ), |
| 44 | array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ), |
| 45 | $class_name |
| 46 | ) |
| 47 | ); |
| 48 | |
| 49 | // Compile our path from the corosponding location. |
| 50 | $file = \ElementsKit_Lite::plugin_dir() . $file_name . '.php'; |
| 51 | |
| 52 | // If a file is found. |
| 53 | if ( file_exists( $file ) ) { |
| 54 | // Then load it up! |
| 55 | require_once $file; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 |