web/lib/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    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-2010 Zend Technologies USA Inc. (http://www.zend.com)
    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
    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
    24  */
    24  */
    25 require_once 'Zend/Http/UserAgent/Features/Adapter.php';
    25 require_once 'Zend/Http/UserAgent/Features/Adapter.php';
    26 
    26 
    27 /**
    27 /**
    28  * Features adapter build with the Tera Wurfl Api
    28  * Features adapter build with the Tera Wurfl Api
    29  * See installation instruction here : http://www.tera-wurfl.com/wiki/index.php/Installation 
    29  * See installation instruction here : http://www.tera-wurfl.com/wiki/index.php/Installation
    30  * Download : http://www.tera-wurfl.com/wiki/index.php/Downloads
    30  * Download : http://www.tera-wurfl.com/wiki/index.php/Downloads
    31  *
    31  *
    32  * @package    Zend_Http
    32  * @package    Zend_Http
    33  * @subpackage UserAgent
    33  * @subpackage UserAgent
    34  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  */
    36  */
    37 class Zend_Http_UserAgent_Features_Adapter_TeraWurfl implements Zend_Http_UserAgent_Features_Adapter
    37 class Zend_Http_UserAgent_Features_Adapter_TeraWurfl implements Zend_Http_UserAgent_Features_Adapter
    38 {
    38 {
    39     /**
    39     /**
    43      * @return array
    43      * @return array
    44      */
    44      */
    45     public static function getFromRequest($request, array $config)
    45     public static function getFromRequest($request, array $config)
    46     {
    46     {
    47         if (!class_exists('TeraWurfl')) {
    47         if (!class_exists('TeraWurfl')) {
    48             // If TeraWurfl class not found, see if we can load it from 
    48             // If TeraWurfl class not found, see if we can load it from
    49             // configuration
    49             // configuration
    50             //
    50             //
    51             if (!isset($config['terawurfl'])) {
    51             if (!isset($config['terawurfl'])) {
    52                 // No configuration
    52                 // No configuration
    53                 require_once 'Zend/Http/UserAgent/Features/Exception.php';
    53                 require_once 'Zend/Http/UserAgent/Features/Exception.php';
    54                 throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined');
    54                 throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined');
    55             }
    55             }
    56             
    56 
    57             $config = $config['terawurfl'];
    57             $config = $config['terawurfl'];
    58 
    58 
    59              if (empty($config['terawurfl_lib_dir'])) {
    59              if (empty($config['terawurfl_lib_dir'])) {
    60                 // No lib_dir given
    60                 // No lib_dir given
    61                 require_once 'Zend/Http/UserAgent/Features/Exception.php';
    61                 require_once 'Zend/Http/UserAgent/Features/Exception.php';
    63             }
    63             }
    64 
    64 
    65             // Include the Tera-WURFL file
    65             // Include the Tera-WURFL file
    66             require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php');
    66             require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php');
    67         }
    67         }
    68         
    68 
    69         
    69 
    70         // instantiate the Tera-WURFL object
    70         // instantiate the Tera-WURFL object
    71         $wurflObj = new TeraWurfl();
    71         $wurflObj = new TeraWurfl();
    72         
    72 
    73         // Get the capabilities of the current client.
    73         // Get the capabilities of the current client.
    74         $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER));
    74         $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER));
    75         
    75 
    76         return self::getAllCapabilities($wurflObj);
    76         return self::getAllCapabilities($wurflObj);
    77     }
    77     }
    78 
    78 
    79     /***
    79     /***
    80      * Builds an array with all capabilities
    80      * Builds an array with all capabilities
    81      * 
    81      *
    82      * @param TeraWurfl $wurflObj TeraWurfl object
    82      * @param TeraWurfl $wurflObj TeraWurfl object
    83      */
    83      */
    84     public static function getAllCapabilities(TeraWurfl $wurflObj)
    84     public static function getAllCapabilities(TeraWurfl $wurflObj)
    85     {
    85     {
    86         
    86 
    87         foreach ($wurflObj->capabilities as $group) {
    87         foreach ($wurflObj->capabilities as $group) {
    88             if (!is_array($group)) {
    88             if (!is_array($group)) {
    89                 continue;
    89                 continue;
    90             }
    90             }
    91             while (list ($key, $value) = each($group)) {
    91             while (list ($key, $value) = each($group)) {