Last active
December 27, 2020 17:55
-
-
Save BlackScorp/5ee1ccc0352766a31f537f8201332400 to your computer and use it in GitHub Desktop.
Code zum Youtube Video https://youtu.be/wK6AVvO-rAI
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 | |
$rootDir = __DIR__.'/classes/'; | |
$autoload = function($className) use($rootDir){ | |
$fileName = ''; | |
if($lastNameSpacePosition = strpos($className,'\\')){ | |
$namespace = substr($className, 0,$lastNameSpacePosition); | |
$className = substr($className,$lastNameSpacePosition+1); | |
$fileName = str_replace('\\',DIRECTORY_SEPARATOR,$namespace).DIRECTORY_SEPARATOR; | |
} | |
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className); | |
if(is_file($rootDir.$fileName.'.php')){ | |
require_once $rootDir.$fileName.'.php'; | |
} | |
}; | |
spl_autoload_register($autoload); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment