Created
August 18, 2010 10:39
-
-
Save f/534291 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Autoloader { | |
public static $prefix = NULL; | |
public static function register($path, $prefix = 'class_') | |
{ | |
self::$prefix = $prefix; | |
if (is_dir($path)) | |
set_include_path($path . PATH_SEPARATOR . get_include_path()); | |
spl_autoload_extensions('.php'); | |
spl_autoload_register(array(__CLASS__, 'loadClass')); | |
} | |
public static function findClassPath($class_name, $extension = NULL, $prefix = 'class_') | |
{ | |
$include_path = explode(PATH_SEPARATOR, get_include_path()); | |
foreach ($include_path as $inc_path) | |
{ | |
if (file_exists($inc_path.DIRECTORY_SEPARATOR.$prefix.$class_name.$extension)) | |
{ | |
return $prefix.$class_name.$extension; | |
} | |
} | |
return false; | |
} | |
public static function loadClass($class_name) | |
{ | |
$class_path = explode('\\',$class_name); | |
$class_name = end($class_path); | |
$extensions = array_map('trim',explode(',',spl_autoload_extensions())); | |
$include_path = get_include_path(); | |
foreach ($extensions as $extension) | |
{ | |
if (false !== ($class_path = self::findClassPath($class_name, $extension, self::$prefix))) | |
{ | |
require $class_path; | |
break; | |
} | |
} | |
} | |
} | |
//kullanimi şu şekilde yaptım | |
Autoloader::register(INTERFACE_CLASS_DIR); | |
Autoloader::register(INTERFACE_CLASS_DIR.'/core/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment