-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoloader.php
49 lines (35 loc) · 898 Bytes
/
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
<?php
/**
* almost PSR-4 autoloader class.
*
*
*/
namespace Blc;
class Autoloader
{
private $base_name_space = 'Blc\\';
private $legacy_dir;
public function __construct()
{
$plugin_path = plugin_dir_path(__FILE__);
$this->legacy_dir = wp_normalize_path(path_join($plugin_path, 'legacy'));
/**
* Register autoloader callback.
*/
spl_autoload_register(array($this, 'autoloader'));
}
public function autoloader($class_name)
{
// If the specified $class_name does not include our namespace, duck out.
if (!str_starts_with($class_name, 'Blc')) {
return;
}
$short_class_name = str_replace($this->base_name_space, '', $class_name);
$class_path = str_replace('\\', DIRECTORY_SEPARATOR, $short_class_name);
$filepath = path_join($this->legacy_dir, $class_path) . '.php';
if (file_exists($filepath)) {
include_once $filepath;
return;
}
}
}