]> git.andy128k.dev Git - ipf.git/commitdiff
modernize autoloader
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Apr 2013 08:47:25 +0000 (11:47 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Apr 2013 08:47:25 +0000 (11:47 +0300)
index.php
ipf.php

index 790368e7111eae79d15efae192461d3c5a6272a2..7e3a3228a979c9db70f79fd82b50b0c9adf64b2b 100644 (file)
--- a/index.php
+++ b/index.php
@@ -4,7 +4,7 @@
 
 $ipf_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ipf';
 $project_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'project';
-set_include_path($ipf_path.PATH_SEPARATOR.$project_path);
+set_include_path(get_include_path() . PATH_SEPARATOR . $ipf_path . PATH_SEPARATOR . $project_path);
 require 'ipf.php';
 IPF::boot($ipf_path, $project_path);
 return IPF_Project::getInstance()->run();
diff --git a/ipf.php b/ipf.php
index af45fb5272b2cf457f84b1f36c80c36ad9c436d8..6dde361de573d5f1b29005f62234537d38542cd1 100644 (file)
--- a/ipf.php
+++ b/ipf.php
@@ -1,10 +1,23 @@
 <?php
 
-function __autoload($class_name)
+function IPF_Autoload($class_name)
 {
-    require_once strtolower(str_replace('_', '/', $class_name)) . '.php';
+    $filename = strtolower(str_replace('_', '/', $class_name)) . '.php';
+    if (file_exists($filename)) {
+        require_once $filename;
+        return;
+    }
+    foreach (explode(PATH_SEPARATOR, get_include_path()) as $dir) {
+        $path = $dir . DIRECTORY_SEPARATOR . $filename;
+        if (file_exists($path)) {
+            require_once($path);
+            break;
+        }
+    }
 }
 
+spl_autoload_register('IPF_Autoload');
+
 final class IPF
 {
     private static $settings = array();