-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautoloader.php
98 lines (79 loc) · 2.29 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace UltraAddons;
defined('ABSPATH') || exit;
/**
* Autoloader for UltraAddons Elementor Lite. All class will call from here by AutoLoader
*
* @author Saiful Islam<[email protected]>
* @since 1.0
* @package UltraAddons
* @link https://www.php.net/manual/en/language.oop5.autoload.php Autoloader Function
*/
class Autoloader {
/**
* Obviously should be lower char
*
* @var type Array
*/
private static $parent_namespace = ['modules','includes','assets'];
/**
* Run autoloader.
*
* Register a function as `__autoload()` implementation.
*
* @since 1.0.0
* @access public
* @static
*/
public static function run() {
spl_autoload_register([ __CLASS__ , 'autoload' ]);
}
/**
* Autoload.
*
* For a given class, check if it exist and load it.
*
* @since 1.0.0
* @access private
* @static
*
* @param string $class Class name.
*/
private static function autoload( $class ) {
if (0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
$filename = strtolower(
preg_replace(
['/\b' . __NAMESPACE__ . '\\\/', '/_/', '/\\\/'], ['', '-', DIRECTORY_SEPARATOR], $class
)
);
$full_class_name = strtolower( preg_replace('/\\\/', DIRECTORY_SEPARATOR, $class ) );
$filepath = ULTRA_ADDONS_DIR . 'inc/' . $filename . '.php';
$filepath = realpath( $filepath );
if ( is_readable( $filepath ) ) {
require_once $filepath;
return;
}
/**
* Pro file Integration
*
* ************************
* First we will find in free version
* then it will search in pro version
*
* amd we will try to open each file using auto loader
* ************************
*
* @since 1.0.27
*/
if( ! defined( 'ULTRA_ADDONS_PRO_DIR' ) ) return;
$filepath = ULTRA_ADDONS_PRO_DIR . 'inc/' . $filename . '.php';
$filepath = realpath( $filepath );
if ( is_readable( $filepath ) ) {
require_once $filepath;
return;
}
}
}
Autoloader::run();