-
Notifications
You must be signed in to change notification settings - Fork 19
/
Autoload.php
93 lines (81 loc) · 2.48 KB
/
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace Geeklog;
/**
* Class Autoload
*
* @package Geeklog
*/
class Autoload
{
/**
* @var bool
*/
private static $initialized = false;
/**
* Load a class
*
* @param string $className
*/
public static function load($className)
{
if (!self::$initialized) {
self::initialize();
}
if (strpos($className, 'Geeklog\\') === 0) {
// New classes under \Geeklog namespace
$className = str_replace('Geeklog\\', '', $className);
$className = ucfirst($className);
$path = __DIR__ . DIRECTORY_SEPARATOR . $className . '.php';
if (file_exists($path)) {
/** @noinspection PhpIncludeInspection */
include $path;
if (method_exists($className, 'init')) {
$className::init();
}
}
} else {
// Legacy Geeklog classes
$path = __DIR__ . DIRECTORY_SEPARATOR . strtolower($className) . '.class.php';
if (file_exists($path)) {
/** @noinspection PhpIncludeInspection */
include $path;
}
if (stripos($className, 'XML_RPC_Server') === 0) {
include __DIR__ . DIRECTORY_SEPARATOR . 'XML/RPC/Server.php';
} elseif (stripos($className, 'XML_RPC_') === 0) {
include __DIR__ . DIRECTORY_SEPARATOR . 'XML/RPC.php';
}
}
}
/**
* Initialize autoloader
*/
public static function initialize()
{
if (!self::$initialized) {
require_once __DIR__ . '/../vendor/autoload.php';
spl_autoload_register('Geeklog\\Autoload::load', true, true);
self::$initialized = true;
}
}
/**
* Register an autoloader
*
* @param callable $autoLoader
* @param bool $throw
* @param bool $prepend
* @throws \InvalidArgumentException
*/
public static function register($autoLoader, $throw = true, $prepend = false)
{
if (!self::$initialized) {
self::initialize();
}
if (!is_callable($autoLoader)) {
throw new \InvalidArgumentException(__METHOD__ . ': $autoLoader must be callable');
}
if (!spl_autoload_register($autoLoader, $throw, $prepend)) {
throw new \InvalidArgumentException(__METHOD__ . ': could not register the autoloader function');
}
}
}