File indexing completed on 2025-05-04 05:32:38

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Http
0017  * @subpackage UserAgent
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 /**
0023  * Zend_Http_UserAgent_Features_Adapter_Interface
0024  */
0025 // require_once 'Zend/Http/UserAgent/Features/Adapter.php';
0026 
0027 /**
0028  * Features adapter utilizing PHP's native browscap support
0029  *
0030  * Requires that you have a PHP-compatible version of the browscap.ini, per the
0031  * instructions at http://php.net/get_browser
0032  *
0033  * @package    Zend_Http
0034  * @subpackage UserAgent
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Http_UserAgent_Features_Adapter_Browscap
0039     implements Zend_Http_UserAgent_Features_Adapter
0040 {
0041     /**
0042      * Constructor
0043      *
0044      * Validate that we have browscap support available.
0045      *
0046      * @throws Zend_Http_UserAgent_Features_Exception
0047      */
0048     public function __construct()
0049     {
0050         $browscap = ini_get('browscap');
0051         if (empty($browscap) || !file_exists($browscap)) {
0052             // require_once 'Zend/Http/UserAgent/Features/Exception.php';
0053             throw new Zend_Http_UserAgent_Features_Exception(sprintf(
0054                 '%s requires a browscap entry in php.ini pointing to a valid browscap.ini; none present',
0055                 __CLASS__
0056             ));
0057         }
0058     }
0059 
0060     /**
0061      * Get features from request
0062      *
0063      * @param  array $request $_SERVER variable
0064      * @param  array $config  ignored; included only to satisfy parent class
0065      * @return array
0066      */
0067     public static function getFromRequest($request, array $config)
0068     {
0069         $browscap = get_browser($request['http_user_agent'], true);
0070         $features = array();
0071 
0072         if (is_array($browscap)) {
0073             foreach ($browscap as $key => $value) {
0074                 // For a few keys, we need to munge a bit for the device object
0075                 switch ($key) {
0076                     case 'browser':
0077                         $features['mobile_browser'] = $value;
0078                         break;
0079 
0080                     case 'version':
0081                         $features['mobile_browser_version'] = $value;
0082                         break;
0083 
0084                     case 'platform':
0085                         $features['device_os'] = $value;
0086                         break;
0087 
0088                     default:
0089                         $features[$key] = $value;
0090                         break;
0091                 }
0092             }
0093         }
0094 
0095         return $features;
0096     }
0097 }