Show
Ignore:
Timestamp:
07/28/09 03:35:26 (3 years ago)
Author:
john
Message:

added the ablility to add additional include_paths and _autoload into autoload to allow for additional functionality to trax's autoload

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/trax.php

    r316 r323  
    6868        $session_maxlifetime_minutes = "20", 
    6969        $version = null, 
    70         $show_trax_errors = false; 
     70        $show_trax_errors = false, 
     71        $server_default_include_path = null, 
     72        $include_paths = array(); 
    7173 
    7274    function initialize() { 
     
    107109        } 
    108110 
    109         # Set the include_path 
    110         ini_set("include_path", 
    111             ".".self::$path_seperator.              # current directory 
    112             TRAX_LIB_ROOT.self::$path_seperator.    # trax libs (vendor/trax or server trax libs) 
    113             PHP_LIB_ROOT.self::$path_seperator.     # php libs dir (ex: /usr/local/lib/php) 
    114             self::$lib_path.self::$path_seperator.  # app specific libs extra libs to include 
    115             ini_get("include_path")                 # tack on the old include_path to the end 
    116         ); 
     111        # Get the include_path so we know what the original path was     
     112        self::$server_default_include_path = ini_get("include_path"); 
     113        # Set the include_paths 
     114        self::set_default_include_paths(); 
    117115 
    118116        # Include Trax library files. 
     
    130128        self::load_active_record_connections_config(); 
    131129 
     130    } 
     131     
     132    function add_include_path($path, $prepend = false, $use_trax_root = false) {  
     133        if(is_array($path)) { 
     134            foreach($path as $new_path) { 
     135                if(!in_array($new_path, self::$include_paths)) { 
     136                    $new_paths[] = $use_trax_root ? TRAX_ROOT."/".$new_path : $new_path;   
     137                } 
     138            } 
     139        } elseif(!in_array($path, self::$include_paths)) { 
     140            $new_paths[] = $use_trax_root ? TRAX_ROOT."/".$path : $path;  
     141        }                         
     142        if(is_array($new_paths) && is_array(self::$include_paths)) {     
     143            foreach($new_paths as $path) { 
     144                if($prepend) { 
     145                    array_unshift(self::$include_paths, $path); 
     146                } else { 
     147                    array_push(self::$include_paths, $path); 
     148                } 
     149            } 
     150            ini_set("include_path", implode(self::$path_seperator, self::$include_paths));             
     151        } 
     152    }  
     153     
     154    function set_default_include_paths() { 
     155        # first clear out all the current paths   
     156        self::$include_paths = array();         
     157        # now add the default paths  
     158        self::add_include_path(array( 
     159            ".",                                # current directory 
     160            TRAX_LIB_ROOT,                      # trax libs (vendor/trax or server trax libs) 
     161            PHP_LIB_ROOT,                       # php libs dir (ex: /usr/local/lib/php) 
     162            self::$lib_path,                    # app specific libs extra libs to include 
     163            self::$server_default_include_path  # tack on the old include_path to the end             
     164        )); 
    132165    }   
     166     
     167    function include_path_exists($path) { 
     168        return in_array($path, self::$include_paths) ? true : false;        
     169    } 
    133170     
    134171    function load_active_record_connections_config() { 
     
    176213        # Include users application libs 
    177214        include_once(Trax::$lib_path."/$file_org"); 
     215    }   
     216           
     217    # add to the __autoload function from Trax 
     218    # just define _autoload() 
     219    if(function_exists('_autoload')) { 
     220        call_user_func('_autoload', $class_name); 
    178221    } 
    179222}