Skip to content

Instantly share code, notes, and snippets.

@BlackScorp
Last active December 27, 2020 17:55
Show Gist options
  • Save BlackScorp/5ee1ccc0352766a31f537f8201332400 to your computer and use it in GitHub Desktop.
Save BlackScorp/5ee1ccc0352766a31f537f8201332400 to your computer and use it in GitHub Desktop.
Code zum Youtube Video https://youtu.be/wK6AVvO-rAI
<?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