Skip to content

Instantly share code, notes, and snippets.

@AnrDaemon
Last active March 3, 2018 23:55
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 AnrDaemon/afafbd1579b2dcac1e55e26fea1e1409 to your computer and use it in GitHub Desktop.
Save AnrDaemon/afafbd1579b2dcac1e55e26fea1e1409 to your computer and use it in GitHub Desktop.
<?php
/** Universal stackable classloader.
*
* @version SVN: $Id: classloader.php 739 2018-03-03 19:05:12Z anrdaemon $
*/
namespace AnrDaemon;
return call_user_func(function(){
$nsl = strlen(__NAMESPACE__);
return spl_autoload_register(
function($className)
use($nsl)
{
if(strncmp($className, __NAMESPACE__, $nsl) !== 0)
return;
$className = substr($className, $nsl);
if(strlen($className) < 2)
return;
$path = realpath(__DIR__ . strtr("$className.php", '\\', '/'));
if(!empty($path))
{
return include_once $path;
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment