Last active
October 17, 2018 17:07
-
-
Save ekandreas/c79af3743bd38e805356b887dbf57ca0 to your computer and use it in GitHub Desktop.
Legacy autoload example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Legacy autoload example | |
*/ | |
spl_autoload_register(function ($requestedClass) { | |
$baseClass='ElseifAB\\Regnradar'; | |
if (0!=strpos($requestedClass, $baseClass.'\\', 0)) { | |
return false; | |
} | |
static $loaded = []; | |
if (isset($loaded[$requestedClass])) { | |
return $loaded[$requestedClass]; | |
} | |
$fileClass = str_replace($baseClass, '', $requestedClass); | |
$fileClass = str_replace('_', '-', $fileClass); | |
$fileClass = str_replace('\\', DIRECTORY_SEPARATOR, $fileClass); | |
$fileClass.='.php'; | |
$fileClass=__DIR__.$fileClass; | |
if (!file_exists($fileClass)) { | |
return false; | |
} | |
return $loaded[$requestedClass] = (bool)require $fileClass; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment