Skip to content

Instantly share code, notes, and snippets.

@tot-ra
Created November 23, 2019 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tot-ra/8a72a80a4b49264a8b3296356930eede to your computer and use it in GitHub Desktop.
Save tot-ra/8a72a80a4b49264a8b3296356930eede to your computer and use it in GitHub Desktop.
Autoloader pseudocode
final class Loader{
// spl_autoload_register([$this, 'loadClass'], true, $prepend);
public function findFile($class){
//...
/* autoload core without namespace classes */
if (is_file($location = ROOTPATH . 'application/core/' . $class . EXT)) {
return $location;
}
/* autoload library classes */
if (is_file($location = ROOTPATH . 'application/libraries/' . $class . EXT)) {
return $location;
}
if (is_file($location = ROOTPATH . 'application/libraries/' . strtolower($class) . EXT)) {
return $location;
}
//... even more dragons..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment