Corrected EA autoload function.
This commit is contained in:
parent
1a651fc718
commit
ea47793dc3
1 changed files with 2 additions and 5 deletions
|
@ -12,13 +12,10 @@
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
function register($namespace, $path) {
|
function register($namespace, $path) {
|
||||||
spl_autoload_register(function ($class) {
|
spl_autoload_register(function ($class) use ($namespace, $path) {
|
||||||
// project-specific namespace prefix
|
// project-specific namespace prefix
|
||||||
$prefix = 'EA\\' . $namespace . '\\';
|
$prefix = 'EA\\' . $namespace . '\\';
|
||||||
|
|
||||||
// base directory for the namespace prefix
|
|
||||||
$base_dir = __DIR__ . '/' . $path;
|
|
||||||
|
|
||||||
// does the class use the namespace prefix?
|
// does the class use the namespace prefix?
|
||||||
$len = strlen($prefix);
|
$len = strlen($prefix);
|
||||||
if (strncmp($prefix, $class, $len) !== 0) {
|
if (strncmp($prefix, $class, $len) !== 0) {
|
||||||
|
@ -32,7 +29,7 @@ function register($namespace, $path) {
|
||||||
// replace the namespace prefix with the base directory, replace namespace
|
// replace the namespace prefix with the base directory, replace namespace
|
||||||
// separators with directory separators in the relative class name, append
|
// separators with directory separators in the relative class name, append
|
||||||
// with .php
|
// with .php
|
||||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
$file = $path . '/' . str_replace('\\', '/', $relative_class) . '.php';
|
||||||
|
|
||||||
// if the file exists, require it
|
// if the file exists, require it
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
|
|
Loading…
Reference in a new issue