Development

Changeset 4154

You must first sign up to be able to contribute.

Changeset 4154

Show
Ignore:
Timestamp:
06/04/07 16:36:42 (6 years ago)
Author:
Jonathan.Todd
Message:

sfBrowserDetectPlugin: Greatly improved performance by storing data in user session

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfBrowserDetectPlugin/lib/sfBrowserDetect.class.php

    r4143 r4154  
    3232class sfBrowserDetect 
    3333{ 
     34   
     35  /** 
     36   * Array with browser info 
     37   * @access private 
     38   * @var array 
     39   */ 
     40  private $browser_info; 
     41   
     42  /** 
     43   * Path to browscap.ini file 
     44   * @access private 
     45   * @var string 
     46   */ 
     47  private $browscap_ini; 
     48   
    3449  function __construct() 
    3550  { 
     51    $browscap_ini = sfConfig::get('app_php_browscap_ini_path',dirname(__FILE__).'/php_browscap.ini'); 
     52 
     53  } 
     54   
     55  /** 
     56   * Intantiates a exiting sfBrowserDetect object 
     57   *  
     58   * @author    Jonathan R. Todd <jtodd@adventexdesign.com> 
     59   */ 
     60  public static function getInstance() 
     61  { 
     62    static $sfBrowserDetect; 
    3663     
     64    if( !isset($sfThumbnailCache) ) 
     65    { 
     66      // Get instance 
     67      $className = sfConfig::get('app_sf_browser_detect_class'); 
     68      $sfBrowserDetect = new $className();   
     69    } 
     70    return $sfBrowserDetect; 
    3771  } 
    3872   
     
    5185   
    5286  /** 
     87   * Get the path for browscap.ini 
     88   *  
     89   * @author    Jonathan R. Todd <jtodd@adventexdesign.com> 
     90   */ 
     91  public function getBrowscapIni() 
     92  { 
     93    return $this->browscap_ini; 
     94  } 
     95   
     96  /** 
     97   * Get browser info array 
     98   *  
     99   * @author    Jonathan R. Todd <jtodd@adventexdesign.com> 
     100   */ 
     101  public function getBrowserInfo() 
     102  { 
     103    if(count($this->browser_info)) 
     104      return $this->browser_info; 
     105    else 
     106      return $this->get_browser_local(null, 
     107        true,$this->browscap_ini,false); 
     108  } 
     109   
     110  /** 
    53111   * Static function which creates sfBrowserDetect object and returns 
    54112   * array with browser info and capabilities 
     
    58116  public static function getBrowser() 
    59117  { 
    60     $ini = sfConfig::get('app_php_browscap_ini_path',null); 
    61     if(!$ini) 
    62       $ini = dirname(__FILE__).'/php_browscap.ini'; 
     118    $user = sfContext::getInstance()->getUser(); 
     119    if(!$user->hasAttribute('browser_info')) 
     120      $user->setAttribute('browser_info', 
     121        self::getInstance()->getBrowserInfo()); 
    63122       
    64     return self::getNewInstance()->get_browser_local(null, 
    65       true,$ini,false); 
     123    return $user->getAttribute('browser_info'); 
    66124  } 
    67125