Last active
July 8, 2020 19:48
-
-
Save mageekguy/8300961 to your computer and use it in GitHub Desktop.
Very simple PSR-4 autoloader
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 | |
namespace your\namespace\here; | |
spl_autoload_register(function($class) { | |
if (stripos($class, __NAMESPACE__) === 0) | |
{ | |
@include(__DIR__ . DIRECTORY_SEPARATOR . 'classes' . str_replace('\\', DIRECTORY_SEPARATOR, strtolower(substr($class, strlen(__NAMESPACE__)))) . '.php'); | |
} | |
} | |
); | |
// Just put this file in the root directory of your project and include it in your bootstrap file and update the namespace. | |
// File name should be lowercase. | |
// File name should have .php extension, if you want using an another extension, update line 8 accordingly. | |
// Search class in "classes" directory, if you want using an another directory, update line 8 accordingly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment