Skip to content

Commit

Permalink
Further Composer adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
jsavell committed Oct 7, 2016
1 parent 6b3cdcd commit 1815262
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
27 changes: 1 addition & 26 deletions Core/Lib/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,10 @@
namespace Core\Lib;
use Core\Classes as CoreClasses;

/*
* This autoloader will search NAMESPACE_APP for a matching file containing the declaration of that class or interface.
*/
spl_autoload_register(function($class) {
loadFile($class,NAMESPACE_APP,PATH_APP);
});
echo 'test';
/*
/**
* This autoloader will search NAMESPACE_CORE for a matching file containing the declaration of that class or interface.
*/

spl_autoload_register(function($class) {
loadFile($class,NAMESPACE_CORE,PATH_CORE);
});

function loadFile($class,$nameSpace,$baseDirectory) {
$len = strlen($nameSpace);
if (strncmp($nameSpace, $class, $len) == 0) {
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $baseDirectory.nameSpaceToPath($class).'.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
}
}

function nameSpaceToPath($nameSpace) {
return str_replace('\\', '/', $nameSpace);
}
18 changes: 18 additions & 0 deletions Core/Lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,22 @@ function getLogger() {
}
return $GLOBALS['logger'];
}

function loadFile($class,$nameSpace,$baseDirectory) {
$len = strlen($nameSpace);
if (strncmp($nameSpace, $class, $len) == 0) {
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $baseDirectory.nameSpaceToPath($class).'.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
}
}

function nameSpaceToPath($nameSpace) {
return str_replace('\\', '/', $nameSpace);
}
?>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"autoload": {
"psr-4": {
"Core\\": "Pipit/"
"Core\\": "/tamu-lib/pipit/Core"
}
}
}

0 comments on commit 1815262

Please sign in to comment.