Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created September 14, 2016 00:57
Show Gist options
  • Save Shelob9/acf3109c006f2957c12ea6b317f549f2 to your computer and use it in GitHub Desktop.
Save Shelob9/acf3109c006f2957c12ea6b317f549f2 to your computer and use it in GitHub Desktop.
<?php
spl_autoload_register(function ($class) {
//change this to your root namespace
$prefix = 'vendor\\rootnamespace\\';
//make sure this is the directory with your classes
$base_dir = __DIR__ . '/classes/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relative_class = substr($class, $len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
if (file_exists($file)) {
require $file;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment