web/lib/Zend/Http/UserAgent/Features/Adapter/Browscap.php
changeset 1230 68c69c656a2c
parent 808 6b6c2214f778
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Http
    16  * @package    Zend_Http
    17  * @subpackage UserAgent
    17  * @subpackage UserAgent
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * Zend_Http_UserAgent_Features_Adapter_Interface
    23  * Zend_Http_UserAgent_Features_Adapter_Interface
    30  * Requires that you have a PHP-compatible version of the browscap.ini, per the
    30  * Requires that you have a PHP-compatible version of the browscap.ini, per the
    31  * instructions at http://php.net/get_browser
    31  * instructions at http://php.net/get_browser
    32  *
    32  *
    33  * @package    Zend_Http
    33  * @package    Zend_Http
    34  * @subpackage UserAgent
    34  * @subpackage UserAgent
    35  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  */
    37  */
    38 class Zend_Http_UserAgent_Features_Adapter_Browscap implements Zend_Http_UserAgent_Features_Adapter
    38 class Zend_Http_UserAgent_Features_Adapter_Browscap
       
    39     implements Zend_Http_UserAgent_Features_Adapter
    39 {
    40 {
    40     /**
    41     /**
    41      * Constructor
    42      * Constructor
    42      *
    43      *
    43      * Validate that we have browscap support available.
    44      * Validate that we have browscap support available.
    44      * 
    45      *
    45      * @return void
       
    46      * @throws Zend_Http_UserAgent_Features_Exception
    46      * @throws Zend_Http_UserAgent_Features_Exception
    47      */
    47      */
    48     public function __construct()
    48     public function __construct()
    49     {
    49     {
    50         $browscap = ini_get('browscap');
    50         $browscap = ini_get('browscap');
    59 
    59 
    60     /**
    60     /**
    61      * Get features from request
    61      * Get features from request
    62      *
    62      *
    63      * @param  array $request $_SERVER variable
    63      * @param  array $request $_SERVER variable
    64      * @param  array $config ignored; included only to satisfy parent class
    64      * @param  array $config  ignored; included only to satisfy parent class
    65      * @return array
    65      * @return array
    66      */
    66      */
    67     public static function getFromRequest($request, array $config)
    67     public static function getFromRequest($request, array $config)
    68     {
    68     {
    69         $browscap = get_browser($request['http_user_agent'], true);
    69         $browscap = get_browser($request['http_user_agent'], true);
    70         $features = array();
    70         $features = array();
    71         foreach ($browscap as $key => $value) {
    71 
    72             // For a few keys, we need to munge a bit for the device object
    72         if (is_array($browscap)) {
    73             switch ($key) {
    73             foreach ($browscap as $key => $value) {
    74                 case 'browser':
    74                 // For a few keys, we need to munge a bit for the device object
    75                     $features['mobile_browser'] = $value;
    75                 switch ($key) {
    76                     break;
    76                     case 'browser':
    77                 case 'version':
    77                         $features['mobile_browser'] = $value;
    78                     $features['mobile_browser_version'] = $value;
    78                         break;
    79                     break;
    79 
    80                 case 'platform':
    80                     case 'version':
    81                     $features['device_os'] = $value;
    81                         $features['mobile_browser_version'] = $value;
    82                     break;
    82                         break;
    83                 default:
    83 
    84                     $features[$key] = $value;
    84                     case 'platform':
    85                     break;
    85                         $features['device_os'] = $value;
       
    86                         break;
       
    87 
       
    88                     default:
       
    89                         $features[$key] = $value;
       
    90                         break;
       
    91                 }
    86             }
    92             }
    87         }
    93         }
       
    94 
    88         return $features;
    95         return $features;
    89     }
    96     }
    90 }
    97 }