|
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-2010 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 build with the Tera Wurfl Api |
|
29 * See installation instruction here : http://deviceatlas.com/licences |
|
30 * Download : http://deviceatlas.com/getAPI/php |
|
31 * |
|
32 * @package Zend_Http |
|
33 * @subpackage UserAgent |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 class Zend_Http_UserAgent_Features_Adapter_DeviceAtlas implements Zend_Http_UserAgent_Features_Adapter |
|
38 { |
|
39 /** |
|
40 * Get features from request |
|
41 * |
|
42 * @param array $request $_SERVER variable |
|
43 * @return array |
|
44 */ |
|
45 public static function getFromRequest($request, array $config) |
|
46 { |
|
47 if (!class_exists('Mobi_Mtld_DA_Api')) { |
|
48 if (!isset($config['deviceatlas'])) { |
|
49 require_once 'Zend/Http/UserAgent/Features/Exception.php'; |
|
50 throw new Zend_Http_UserAgent_Features_Exception('"DeviceAtlas" configuration is not defined'); |
|
51 } |
|
52 } |
|
53 |
|
54 $config = $config['deviceatlas']; |
|
55 |
|
56 if (!class_exists('Mobi_Mtld_DA_Api')) { |
|
57 if (empty($config['deviceatlas_lib_dir'])) { |
|
58 require_once 'Zend/Http/UserAgent/Features/Exception.php'; |
|
59 throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_lib_dir" parameter is not defined'); |
|
60 } |
|
61 |
|
62 // Include the Device Atlas file from the specified lib_dir |
|
63 require_once ($config['deviceatlas_lib_dir'] . '/Mobi/Mtld/DA/Api.php'); |
|
64 } |
|
65 |
|
66 if (empty($config['deviceatlas_data'])) { |
|
67 require_once 'Zend/Http/UserAgent/Features/Exception.php'; |
|
68 throw new Zend_Http_UserAgent_Features_Exception('The "deviceatlas_data" parameter is not defined'); |
|
69 } |
|
70 |
|
71 //load the device data-tree : e.g. 'json/DeviceAtlas.json |
|
72 $tree = Mobi_Mtld_DA_Api::getTreeFromFile($config['deviceatlas_data']); |
|
73 |
|
74 $properties = Mobi_Mtld_DA_Api::getProperties($tree, $request['http_user_agent']); |
|
75 |
|
76 return $properties; |
|
77 } |
|
78 } |