Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace System\Core;
- class Loader
- {
- private static $fileExtension = '.php';
- private static function autoload($className)
- {
- $fileName = '';
- $namespace = '';
- if (false !== ($lastNsPos = strripos($className, '\\'))) {
- $namespace = substr($className, 0, $lastNsPos);
- $className = substr($className, $lastNsPos + 1);
- $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
- }
- $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . self::$fileExtension;
- try {
- include BASEPATH . $fileName;
- }
- catch (Exception $e) {
- echo 'Loader::autoload exception catched: ', $e->getMessage(), '<br><br>';
- }
- }
- public static function splRegister()
- {
- spl_autoload_register('self::autoload');
- }
- public static function splUnRegister()
- {
- spl_autoload_unregister('self::autoload');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement