forked from Dan0sz/host-everything-locally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoosh-autoload.php
74 lines (64 loc) · 1.97 KB
/
woosh-autoload.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
<?php
/* * * * * * * * * * * * * * * * * * * * * *
* _ __ ____ _____ __ ____
* | | / /___ / __ \/ ___// / / / /
* | | /| / / __ \/ / / /\__ \/ /_/ / /
* | |/ |/ / /_/ / /_/ /___/ / __ /_/
* |__/|__/\____/\____//____/_/ /_(_)
*
* @author : Daan van den Bergh
* @url : https://woosh.dev/wordpress-plugins/
* @copyright: (c) 2020 Daan van den Bergh
* @license : GPL2v2 or later
* * * * * * * * * * * * * * * * * * * * * */
class Woosh_Autoloader
{
/** @var string $class */
private $class;
/** @var string $file */
private $file;
/**
* Woosh_Autoloader constructor.
*
* @param $class
*/
public function __construct(
$class
) {
$this->class = $class;
$this->load();
}
/**
* Build filepath for requested class.
*/
public function load()
{
$path = explode('_', $this->class);
$this->file = '';
if (count($path) == 1) {
if (ctype_upper($path[0])) {
$this->file = 'class-' . strtolower(str_replace('_', '-', $this->class)) . '.php';
} else {
$parts = preg_split('/(?=[A-Z])/', lcfirst($path[0]));
$this->file = 'class-' . strtolower(implode('-', $parts)) . '.php';
}
} else {
array_shift($path);
end($path);
$i = 0;
while ($i < key($path)) {
$this->file .= strtolower($path[$i]) . '/';
$i++;
}
// If entire part of path is written uppercase, we don't want to split.
if (ctype_upper($path[$i])) {
$pieces[] = $path[$i];
// Words like OmgfPro or SuperStealth should be split up.
} else {
$pieces = preg_split('/(?=[A-Z])/', lcfirst($path[$i]));
}
$this->file .= 'class-' . strtolower(implode('-', $pieces)) . '.php';
}
return $this->file;
}
}