-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoloader.php
70 lines (54 loc) · 1.57 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
<?php
namespace WC_MMQ;
if( ! class_exists( 'WC_MMQ\Autoloader' ) ){
/**
* Autoloader: All class will call from here by AutoLoader
*
* @author Saiful Islam<[email protected]>
* @since 1.0.0.8
* @package CA Framework
* @link https://www.php.net/manual/en/language.oop5.autoload.php Autoloader Function
*/
class Autoloader
{
/**
* 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.8
* @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
)
);
$filename = __DIR__. '/' . $filename . '.php';
$filename = realpath( $filename );
if ( is_readable( $filename ) ) {
require_once $filename;
}
}
}
Autoloader::run();
}