web/lib/Zend/Http/UserAgent/Features/Adapter/Browscap.php
changeset 808 6b6c2214f778
child 1230 68c69c656a2c
equal deleted inserted replaced
807:877f952ae2bd 808:6b6c2214f778
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Http
       
    17  * @subpackage UserAgent
       
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  */
       
    21 
       
    22 /**
       
    23  * Zend_Http_UserAgent_Features_Adapter_Interface
       
    24  */
       
    25 require_once 'Zend/Http/UserAgent/Features/Adapter.php';
       
    26 
       
    27 /**
       
    28  * Features adapter utilizing PHP's native browscap support
       
    29  *
       
    30  * Requires that you have a PHP-compatible version of the browscap.ini, per the
       
    31  * instructions at http://php.net/get_browser
       
    32  *
       
    33  * @package    Zend_Http
       
    34  * @subpackage UserAgent
       
    35  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
       
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    37  */
       
    38 class Zend_Http_UserAgent_Features_Adapter_Browscap implements Zend_Http_UserAgent_Features_Adapter
       
    39 {
       
    40     /**
       
    41      * Constructor
       
    42      *
       
    43      * Validate that we have browscap support available.
       
    44      * 
       
    45      * @return void
       
    46      * @throws Zend_Http_UserAgent_Features_Exception
       
    47      */
       
    48     public function __construct()
       
    49     {
       
    50         $browscap = ini_get('browscap');
       
    51         if (empty($browscap) || !file_exists($browscap)) {
       
    52             require_once 'Zend/Http/UserAgent/Features/Exception.php';
       
    53             throw new Zend_Http_UserAgent_Features_Exception(sprintf(
       
    54                 '%s requires a browscap entry in php.ini pointing to a valid browscap.ini; none present',
       
    55                 __CLASS__
       
    56             ));
       
    57         }
       
    58     }
       
    59 
       
    60     /**
       
    61      * Get features from request
       
    62      *
       
    63      * @param  array $request $_SERVER variable
       
    64      * @param  array $config ignored; included only to satisfy parent class
       
    65      * @return array
       
    66      */
       
    67     public static function getFromRequest($request, array $config)
       
    68     {
       
    69         $browscap = get_browser($request['http_user_agent'], true);
       
    70         $features = array();
       
    71         foreach ($browscap as $key => $value) {
       
    72             // For a few keys, we need to munge a bit for the device object
       
    73             switch ($key) {
       
    74                 case 'browser':
       
    75                     $features['mobile_browser'] = $value;
       
    76                     break;
       
    77                 case 'version':
       
    78                     $features['mobile_browser_version'] = $value;
       
    79                     break;
       
    80                 case 'platform':
       
    81                     $features['device_os'] = $value;
       
    82                     break;
       
    83                 default:
       
    84                     $features[$key] = $value;
       
    85                     break;
       
    86             }
       
    87         }
       
    88         return $features;
       
    89     }
       
    90 }