DeviceAtlas.php 2.7 KB

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