-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoloader.php
49 lines (42 loc) · 1.43 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
<?php
/*
* This file is part of the ACF Collector plugin.
*
* (c) Alfredo Aiello <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Automatically loads the specified file.
*/
define('ACF_COLLECTOR_BASE_NAMESPACE', 'ACFCollector');
define('ACF_COLLECTOR_SOURCE', 'src' . DIRECTORY_SEPARATOR);
/**
* Automatically loads the specified file.
* Examines the fully qualified class name, separates it into components, then creates
* a string that represents where the file is loaded on disk.
* @since 1.0.0
*/
spl_autoload_register('acfCollectorAutoload');
function acfCollectorAutoload($requestClassNamespace)
{
/**
* If the class being requested does not start with our prefix,
* we know it's not one in our project
*/
if (0 !== strpos($requestClassNamespace, ACF_COLLECTOR_BASE_NAMESPACE)) {
return;
}
$startFolder = sprintf('%s%s', ACF_COLLECTOR_PATH, ACF_COLLECTOR_SOURCE);
$firstBackslashIndex = strpos($requestClassNamespace, '\\');
$relativePath = str_replace('\\', DIRECTORY_SEPARATOR, substr($requestClassNamespace, $firstBackslashIndex + 1));
$classFullPath = sprintf('%s%s.php', $startFolder, $relativePath);
/**
* If the class file not exists, we can't require it
*/
if (!file_exists($classFullPath)) {
return false;
}
require_once $classFullPath;
}