-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautoload.php
29 lines (25 loc) · 1.07 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
<?php
/**
* Load a Caliper class file based on its name.
*
* @param string $className Fully-qualified name of class to be loaded
*/
$loadCaliperClass = function ($className) {
/** @var string $classBaseDirectory Base directory for class files, i.e., "./src/" */
$classBaseDirectory = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
// If the class name begins with "IMSGlobal\Caliper\", remove it
if (strpos($className, 'IMSGlobal\\Caliper\\') === 0) {
$className = substr($className, 18);
}
// Construct the class' filename from the class base directory, the class name
// with slashes replaced by the OS-specific directory separator character, and
// the ".php" extension
/** @var string $classFileFullPath */
$classFileFullPath = $classBaseDirectory .
str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $className) . '.php';
// If the class file exists, require it, but only once
if (file_exists($classFileFullPath)) {
require_once $classFileFullPath;
}
};
spl_autoload_register($loadCaliperClass);