Skip to content

Instantly share code, notes, and snippets.

@loraxx753
Created September 13, 2013 04:32
Show Gist options
  • Save loraxx753/6546810 to your computer and use it in GitHub Desktop.
Save loraxx753/6546810 to your computer and use it in GitHub Desktop.
<?php
function __autoload($class_name)
{
$fileName = '';
if(strpos($class_name, "\\") === false) {
$fileName = '/corename/app/classes' . DIRECTORY_SEPARATOR;
}
$className = ltrim($class_name, '\\');
$namespace = '';
if ($lastNsPos = strrpos($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) . '.php';
$fileName = strtolower($fileName);
if(file_exists(PROJECTROOT . $fileName))
{
require PROJECTROOT . $fileName;
}
else
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment