elementskit-lite
Last commit date
assets
3 weeks ago
compatibility
3 weeks ago
config
3 weeks ago
core
3 weeks ago
helpers
3 weeks ago
languages
3 weeks ago
libs
3 weeks ago
mcp
3 weeks ago
modules
3 weeks ago
traits
4 years ago
widgets
3 weeks ago
autoloader.php
3 weeks ago
elementskit-lite.php
3 weeks ago
plugin.php
3 weeks ago
readme.txt
3 weeks ago
wpml-config.xml
3 weeks ago
autoloader.php
64 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | /** |
| 7 | * ElementsKit_Lite legacy autoloader. |
| 8 | * |
| 9 | * Handles dynamically loading legacy (non-PSR-4) classes under the |
| 10 | * `ElementsKit_Lite` namespace that use underscore-style naming. |
| 11 | * |
| 12 | * New code should use PSR-4 namespaces (e.g. `ElementsKit\Lite\Core\...`) |
| 13 | * and rely on Composer's autoloader (`vendor/autoload.php`) instead. |
| 14 | * |
| 15 | * @since 1.0.0 |
| 16 | */ |
| 17 | class Autoloader { |
| 18 | |
| 19 | /** |
| 20 | * Run autoloader. |
| 21 | * |
| 22 | * Registers this class's `autoload()` method as an SPL autoloader. |
| 23 | * |
| 24 | * @since 1.0.0 |
| 25 | * @access public |
| 26 | * @return void |
| 27 | */ |
| 28 | public static function run() { |
| 29 | spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Autoload. |
| 34 | * |
| 35 | * For a given class name, resolve the corresponding file path and |
| 36 | * load it if it exists. |
| 37 | * |
| 38 | * @since 1.0.0 |
| 39 | * @access private |
| 40 | * @param string $class_name Fully qualified class name. |
| 41 | * @return void |
| 42 | */ |
| 43 | private static function autoload( $class_name ) { |
| 44 | |
| 45 | // Bail early if the class isn't part of this namespace. |
| 46 | if ( 0 !== strpos( $class_name, __NAMESPACE__ ) ) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | $file_name = strtolower( |
| 51 | preg_replace( |
| 52 | array( '/\b' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ), |
| 53 | array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ), |
| 54 | $class_name |
| 55 | ) |
| 56 | ); |
| 57 | |
| 58 | $file = \ElementsKit_Lite::plugin_dir() . $file_name . '.php'; |
| 59 | |
| 60 | if ( file_exists( $file ) ) { |
| 61 | require_once $file; |
| 62 | } |
| 63 | } |
| 64 | } |