-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.php
33 lines (29 loc) · 967 Bytes
/
Loader.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
<?php
class Loader
{
public static $vendor_map = [
'crawler' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'crawler',
'resource' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'resource',
'worker' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'worker'
];
public static function autoload($class)
{
$file = self::findClassFile($class);
if (file_exists($file)) {
static::includeFile($file);
}
}
private static function findClassFile($class)
{
$vendor = substr($class, 0, strpos($class, '\\'));
$vendor_dir = static::$vendor_map[$vendor];
$file_path = substr($class, strlen($vendor)) . '.php';
return strtr($vendor_dir . $file_path, '\\', DIRECTORY_SEPARATOR);
}
private static function includeFile($file)
{
if (is_file($file)) {
require $file;
}
}
}