File indexing completed on 2025-01-19 05:21:14
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 build with the Tera Wurfl Api 0029 * See installation instruction here : http://www.tera-wurfl.com/wiki/index.php/Installation 0030 * Download : http://www.tera-wurfl.com/wiki/index.php/Downloads 0031 * 0032 * @package Zend_Http 0033 * @subpackage UserAgent 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Http_UserAgent_Features_Adapter_TeraWurfl implements Zend_Http_UserAgent_Features_Adapter 0038 { 0039 /** 0040 * Get features from request 0041 * 0042 * @param array $request $_SERVER variable 0043 * @return array 0044 */ 0045 public static function getFromRequest($request, array $config) 0046 { 0047 if (!class_exists('TeraWurfl')) { 0048 // If TeraWurfl class not found, see if we can load it from 0049 // configuration 0050 // 0051 if (!isset($config['terawurfl'])) { 0052 // No configuration 0053 // require_once 'Zend/Http/UserAgent/Features/Exception.php'; 0054 throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined'); 0055 } 0056 0057 $config = $config['terawurfl']; 0058 0059 if (empty($config['terawurfl_lib_dir'])) { 0060 // No lib_dir given 0061 // require_once 'Zend/Http/UserAgent/Features/Exception.php'; 0062 throw new Zend_Http_UserAgent_Features_Exception('The "terawurfl_lib_dir" parameter is not defined'); 0063 } 0064 0065 // Include the Tera-WURFL file 0066 // require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php'); 0067 } 0068 0069 0070 // instantiate the Tera-WURFL object 0071 $wurflObj = new TeraWurfl(); 0072 0073 // Get the capabilities of the current client. 0074 $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER)); 0075 0076 return self::getAllCapabilities($wurflObj); 0077 } 0078 0079 /*** 0080 * Builds an array with all capabilities 0081 * 0082 * @param TeraWurfl $wurflObj TeraWurfl object 0083 */ 0084 public static function getAllCapabilities(TeraWurfl $wurflObj) 0085 { 0086 0087 foreach ($wurflObj->capabilities as $group) { 0088 if (!is_array($group)) { 0089 continue; 0090 } 0091 while (list ($key, $value) = each($group)) { 0092 if (is_bool($value)) { 0093 // to have the same type than the official WURFL API 0094 $features[$key] = ($value ? 'true' : 'false'); 0095 } else { 0096 $features[$key] = $value; 0097 } 0098 } 0099 } 0100 return $features; 0101 } 0102 }