forked from elementor/elementor-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoloader.php
53 lines (46 loc) · 1.02 KB
/
autoloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace ElementorBeta;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Autoloader {
/**
* Run autoloader.
*/
public static function run() {
spl_autoload_register( [ __CLASS__, 'autoload' ] );
}
/**
* Autoload.
*
* For a given class, check if it exist and load it.
*
* @param $class
*/
private static function autoload( $class ) {
if ( ! class_exists( $class ) ) {
self::load_class( $class );
}
}
/**
* Load class.
*
* For a given class name, require the class file.
*
* @param $relative_class_name
*/
private static function load_class( $relative_class_name ) {
$relative_class_name = str_replace( ELEMENTOR_BETA_NAMESPACE . '\\', '', $relative_class_name );
$filename = strtolower(
preg_replace(
[ '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '$1-$2', '-', DIRECTORY_SEPARATOR ],
$relative_class_name
)
);
$filename = ELEMENTOR_BETA_DIR . $filename . '.php';
if ( is_readable( $filename ) ) {
require_once $filename;
}
}
}