Changeset 251 for trunk

Show
Ignore:
Timestamp:
08/26/06 10:27:55 (6 years ago)
Author:
john
Message:

move database_settings[] and active_connections[] to AR out of Trax class to make AR more generic for standalone version

Location:
trunk/trax/vendor/trax
Files:
2 modified

Legend:

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

    r250 r251  
    139139     
    140140    /** 
    141      *  Index into the Trax::$active_record_connections array 
     141     *  Index into the $active_connections array 
    142142     * 
    143143     *  Name of the index to use to return or set the current db connection 
     
    147147     */     
    148148    public $connection_name = TRAX_ENV; 
     149 
     150    /** 
     151     * Stores the database settings 
     152     */ 
     153    public static $database_settings = array(); 
     154     
     155    /** 
     156     * Stores the active connections 
     157     */ 
     158    public static $active_connections = array(); 
    149159 
    150160    /** 
     
    12671277         
    12681278                # Set number of total pages in result set   
    1269                 if($count = $this->count_all("*", $conditions, $joins)) { 
     1279                if($count = $this->count_all($this->primary_keys[0], $conditions, $joins)) { 
    12701280                    $this->pagination_count = $count; 
    12711281                    $this->pages = ( 
     
    23102320     * 
    23112321     *  The name of the database normally comes from 
    2312      *  Trax::$database_settings which is set in {@link 
     2322     *  $database_settings which is set in {@link 
    23132323     *  environment.php} by reading file config/database.ini. The 
    23142324     *  database name may be overridden by assigning a different name 
     
    23162326     *   
    23172327     *  If there is a connection now open, as indicated by the saved 
    2318      *  value of a DB object in Trax::$active_record_connections[$connection_name], and 
     2328     *  value of a MDB2 object in $active_connections[$connection_name], and 
    23192329     *  {@link force_reconnect} is not true, then set the database 
    23202330     *  fetch mode and return. 
    23212331     * 
    23222332     *  If there is no connection, open one and save a reference to 
    2323      *  it in Trax::$active_record_connections[$connection_name]. 
     2333     *  it in $active_connections[$connection_name]. 
    23242334     * 
    23252335     *  @uses $db 
    23262336     *  @uses $database_name 
    23272337     *  @uses $force_reconnect 
    2328      *  @uses Trax::$active_record_connections 
     2338     *  @uses $active_connections 
    23292339     *  @uses is_error() 
    23302340     *  @throws {@link ActiveRecordError} 
    23312341     */ 
    23322342    function establish_connection() { 
    2333         $connection =& Trax::$active_record_connections[$this->connection_name]; 
     2343        $connection =& self::$active_connections[$this->connection_name]; 
    23342344        if(!is_object($connection) || $this->force_reconnect) { 
    2335             if(array_key_exists($this->connection_name, Trax::$database_settings)) { 
     2345            if(array_key_exists($this->connection_name, self::$database_settings)) { 
    23362346                 # Use a different custom sections settings ? 
    2337                 if(array_key_exists("use", Trax::$database_settings[$this->connection_name])) { 
    2338                     $connection_settings = Trax::$database_settings[Trax::$database_settings[$this->connection_name]['use']]; 
     2347                if(array_key_exists("use", self::$database_settings[$this->connection_name])) { 
     2348                    $connection_settings = self::$database_settings[self::$database_settings[$this->connection_name]['use']]; 
    23392349                } else { 
    23402350                    # Custom defined db settings in database.ini  
    2341                     $connection_settings = Trax::$database_settings[$this->connection_name]; 
     2351                    $connection_settings = self::$database_settings[$this->connection_name]; 
    23422352                } 
    23432353            } else { 
     
    23462356                # if should never really get here unless override $this->connection_name 
    23472357                # and you define a custom db section in database.ini and it can't find it. 
    2348                 $connection_settings = Trax::$database_settings[TRAX_ENV]; 
     2358                $connection_settings = self::$database_settings[TRAX_ENV]; 
    23492359            } 
    23502360            # Override database name if param is set 
     
    23612371        } 
    23622372        if(!$this->is_error($connection)) { 
    2363             Trax::$active_record_connections[$this->connection_name] =& $connection; 
     2373            self::$active_connections[$this->connection_name] =& $connection; 
    23642374            self::$db =& $connection; 
    23652375        } else { 
  • trunk/trax/vendor/trax/trax.php

    r208 r251  
    4848        $vendor_path = null, 
    4949        $public_path = null, 
    50         $database_settings = array(),  
    5150        $url_prefix = null, 
    5251        $views_extension = 'phtml', 
    5352        $path_seperator = ":", # default is Unix 
    54         $active_record_connections = array(), 
    5553        $current_controller_path = null, 
    5654        $current_controller_name = null, 
     
    9290            ini_set("display_errors", "Off"); 
    9391        } 
    94          
    95         # Make sure database settings are cleared out 
    96         self::$database_settings = array(); 
    97         if(file_exists(self::$config_path."/database.ini")) { 
    98             # Load databse settings  
    99             self::$database_settings = parse_ini_file(self::$config_path."/database.ini",true); 
    100         } 
    101          
     92                 
    10293        # Set the include_path 
    10394        ini_set("include_path", 
     
    119110        include_once("dispatcher.php"); 
    120111        include_once("router.php"); 
     112 
     113        # Make sure database settings are cleared out 
     114        ActiveRecord::$database_settings = array(); 
     115        if(file_exists(self::$config_path."/database.ini")) { 
     116            # Load databse settings  
     117            ActiveRecord::$database_settings = parse_ini_file(self::$config_path."/database.ini", true); 
     118        } 
    121119                    
    122120    }