Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. spl_autoload_register(function ($strClass) {
  2.     $strFile = $strClass . '.php';
  3.     $strNameSpace = '';
  4.  
  5.     if (($iLast = strripos($strClass, '\\')) !== false) {
  6.         $strNameSpace = DS . str_replace('\\', DS, substr($strClass, 0, $iLast));
  7.         $strNameSpace = implode('_', preg_split('/(?<=[a-zA-Z])(?=[A-Z])/s', $strNameSpace));
  8.         $strFile = substr($strClass, $iLast + 1) . '.php';
  9.     }
  10.  
  11.     $strFilePath = ROOT . strtolower($strNameSpace) . DS . $strFile;
  12.     if (is_readable($strFilePath)) {
  13.         require_once $strFilePath;
  14.  
  15.         if (class_exists($strClass)) {
  16.             return true;
  17.         }
  18.     }
  19.  
  20.     return false;
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement