Created
April 17, 2025 07:27
-
-
Save tayyebi/ca340e0d00a17f90b8d019d20a48a701 to your computer and use it in GitHub Desktop.
PHP Auto-loader
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 | |
spl_autoload_register(function (string $class_name): void { | |
$namespace = 'Gordarg'; | |
if (strpos($class_name, $namespace) === 0) { | |
$class_file = ROOT_PATH . 'src'; | |
$class_file .= | |
str_replace( | |
[$namespace, '\\'], | |
['', DIRECTORY_SEPARATOR], | |
$class_name | |
) | |
. '.php'; | |
if (file_exists($class_file)) { | |
require_once $class_file; | |
return; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment