-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoloader.php
32 lines (24 loc) · 1.04 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
<?php
namespace Entase\Plugins\WP;
function AutoLoader($className)
{
if (strpos($className, 'Entase\\Plugins\\WP\\') !== 0)
return;
$calledClass = $className;
$className = str_replace('Entase\\Plugins\\WP\\', '', $className);
$fileName = '';
$namespace = '';
$includePath = dirname(__FILE__).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR;
if (false !== ($lastNsPos = strripos($className, '\\'))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$fullFilePath = $includePath.DIRECTORY_SEPARATOR.$fileName;
if (file_exists($fullFilePath)) {
require_once $fullFilePath;
}
else { echo $fullFilePath."\r\n\r\n"; die('Class "'.$calledClass.'" does not exist.'); }
}
\spl_autoload_register('Entase\\Plugins\\WP\\AutoLoader'); // Registers the autoloader