Corrected EA autoload function.

This commit is contained in:
Alex Tselegidis 2016-07-09 10:23:40 +02:00
parent 1a651fc718
commit ea47793dc3

View file

@ -12,13 +12,10 @@
* ---------------------------------------------------------------------------- */
function register($namespace, $path) {
spl_autoload_register(function ($class) {
spl_autoload_register(function ($class) use ($namespace, $path) {
// project-specific namespace prefix
$prefix = 'EA\\' . $namespace . '\\';
// base directory for the namespace prefix
$base_dir = __DIR__ . '/' . $path;
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
@ -32,7 +29,7 @@ function register($namespace, $path) {
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
$file = $path . '/' . str_replace('\\', '/', $relative_class) . '.php';
// if the file exists, require it
if (file_exists($file)) {