Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TeraWurfl.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Http/UserAgent/Features/Adapter.php';
26 
38 {
45  public static function getFromRequest($request, array $config)
46  {
47  if (!class_exists('TeraWurfl')) {
48  // If TeraWurfl class not found, see if we can load it from
49  // configuration
50  //
51  if (!isset($config['terawurfl'])) {
52  // No configuration
53  #require_once 'Zend/Http/UserAgent/Features/Exception.php';
54  throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined');
55  }
56 
57  $config = $config['terawurfl'];
58 
59  if (empty($config['terawurfl_lib_dir'])) {
60  // No lib_dir given
61  #require_once 'Zend/Http/UserAgent/Features/Exception.php';
62  throw new Zend_Http_UserAgent_Features_Exception('The "terawurfl_lib_dir" parameter is not defined');
63  }
64 
65  // Include the Tera-WURFL file
66  #require_once ($config['terawurfl_lib_dir'] . '/TeraWurfl.php');
67  }
68 
69 
70  // instantiate the Tera-WURFL object
71  $wurflObj = new TeraWurfl();
72 
73  // Get the capabilities of the current client.
74  $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER));
75 
76  return self::getAllCapabilities($wurflObj);
77  }
78 
79  /***
80  * Builds an array with all capabilities
81  *
82  * @param TeraWurfl $wurflObj TeraWurfl object
83  */
84  public static function getAllCapabilities(TeraWurfl $wurflObj)
85  {
86 
87  foreach ($wurflObj->capabilities as $group) {
88  if (!is_array($group)) {
89  continue;
90  }
91  foreach ($group as $key => $value) {
92  if (is_bool($value)) {
93  // to have the same type than the official WURFL API
94  $features[$key] = ($value ? 'true' : 'false');
95  } else {
96  $features[$key] = $value;
97  }
98  }
99  }
100  return $features;
101  }
102 }
static getFromRequest($request, array $config)
Definition: TeraWurfl.php:45
$config
Definition: fraud_order.php:17
$group
Definition: sections.phtml:16
$value
Definition: gender.phtml:16
static getAllCapabilities(TeraWurfl $wurflObj)
Definition: TeraWurfl.php:84