PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/Zend/Http/UserAgent/Features/Adapter/WurflApi.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 103 lines | 55 code | 9 blank | 39 comment | 7 complexity | 8cab2b0c8fb609db08228e63aa26834d MD5 | raw file
  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-2011 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 official WURFL PHP API
  27. * See installation instruction here : http://wurfl.sourceforge.net/nphp/
  28. * Download : http://sourceforge.net/projects/wurfl/files/WURFL PHP/1.1/wurfl-php-1.1.tar.gz/download
  29. *
  30. * @package Zend_Http
  31. * @subpackage UserAgent
  32. * @copyright Copyright (c) 2005-2011 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_WurflApi
  36. implements Zend_Http_UserAgent_Features_Adapter
  37. {
  38. const DEFAULT_API_VERSION = '1.1';
  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 (!isset($config['wurflapi'])) {
  48. require_once 'Zend/Http/UserAgent/Features/Exception.php';
  49. throw new Zend_Http_UserAgent_Features_Exception('"wurflapi" configuration is not defined');
  50. }
  51. $config = $config['wurflapi'];
  52. if (empty($config['wurfl_lib_dir'])) {
  53. require_once 'Zend/Http/UserAgent/Features/Exception.php';
  54. throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_lib_dir" parameter is not defined');
  55. }
  56. if (empty($config['wurfl_config_file']) && empty($config['wurfl_config_array'])) {
  57. require_once 'Zend/Http/UserAgent/Features/Exception.php';
  58. throw new Zend_Http_UserAgent_Features_Exception('The "wurfl_config_file" parameter is not defined');
  59. }
  60. if (empty($config['wurfl_api_version'])) {
  61. $config['wurfl_api_version'] = self::DEFAULT_API_VERSION;
  62. }
  63. switch ($config['wurfl_api_version']) {
  64. case '1.0':
  65. // Zend_Http_UserAgent::$config['wurfl_config_file'] must be an XML file
  66. require_once ($config['wurfl_lib_dir'] . 'WURFLManagerProvider.php');
  67. $wurflManager = WURFL_WURFLManagerProvider::getWURFLManager(Zend_Http_UserAgent::$config['wurfl_config_file']);
  68. break;
  69. case '1.1':
  70. require_once ($config['wurfl_lib_dir'] . 'Application.php');
  71. if (!empty($config['wurfl_config_file'])) {
  72. $wurflConfig = WURFL_Configuration_ConfigFactory::create($config['wurfl_config_file']);
  73. } elseif (!empty($config['wurfl_config_array'])) {
  74. $c = $config['wurfl_config_array'];
  75. $wurflConfig = new WURFL_Configuration_InMemoryConfig();
  76. $wurflConfig->wurflFile($c['wurfl']['main-file'])
  77. ->wurflPatch($c['wurfl']['patches'])
  78. ->persistence($c['persistence']['provider'], $c['persistence']['dir']);
  79. }
  80. $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);
  81. $wurflManager = $wurflManagerFactory->create();
  82. break;
  83. default:
  84. require_once 'Zend/Http/UserAgent/Features/Exception.php';
  85. throw new Zend_Http_UserAgent_Features_Exception(sprintf(
  86. 'Unknown API version "%s"',
  87. $config['wurfl_api_version']
  88. ));
  89. }
  90. $device = $wurflManager->getDeviceForHttpRequest(array_change_key_case($request, CASE_UPPER));
  91. $features = $device->getAllCapabilities();
  92. return $features;
  93. }
  94. }