function test_formatTime($time) { return number_format($time * 1000, 1) . ' ms'; } $start_time = microtime(true); require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../UserAgentInfoPeer.class.php'; $start_time = test_formatTime(microtime(true) - $start_time); $my_time = microtime(true); $my_ua_string = UserAgentInfoPeer::getMy()->getUserAgentString(); $my_time = test_formatTime(microtime(true) - $my_time); $user_agents = explode("\n", trim(file_get_contents(UserAgentInfoConfig::$base_dir . UserAgentInfoConfig::DIR_TESTS . DIRECTORY_SEPARATOR . 'user-agent-examples.txt'))); array_unshift($user_agents, $my_ua_string, 'Random UA 1 (no match): ' . uniqid(null, true), 'Random UA 2 (no match): ' . uniqid(null, true), 'Random UA 3 (no match): ' . uniqid(null, true)); $results = array(); foreach ($user_agents as $i => $one_ua) { $t = microtime(true); $mua = UserAgentInfoPeer::getOther($one_ua, true); $t = test_formatTime(microtime(true) - $t); if ($mua->isMobileAndroid()) { $mobile_info = $mua->isMobileTablet() ? 'Android tablet' : 'Android'; } elseif ($mua->isMobileAppleIos()) { $mobile_info = $mua->isMobileTablet() ? 'iPad' : 'iPhone'; } elseif ($mua->isMobile()) { $mobile_info = $mua->isMobileTablet() ? 'tablet' : 'mobile'; } else { $mobile_info = ''; } $results[md5($mua->getUserAgentString())] = array($i, $t, $mua->isIdentifiedFully() ? '' : ($mua->isIdentified() ? '?' : 'x'), $mua->getUserAgentString(), $mua->renderInfoBrowser(true), $mua->renderInfoOs(true), $mua->renderInfoDevice(), $mua->getMobileGrade() ? 'grade ' . $mua->getMobileGrade() : '', $mua->isBanned() ? 'banned' : '', $mua->isBot() ? $mua->isBotReader() ? 'reader' : 'bot' : '', $mobile_info); } $old_results = call_user_func(array(UserAgentInfoConfig::CACHE_CLASS_NAME, 'get'), 'test-archive-of-user-agents'); call_user_func(array(UserAgentInfoConfig::CACHE_CLASS_NAME, 'set'), 'test-archive-of-user-agents', $results); $old_md5 = md5(serialize($old_results));
/** * Prepares the list data */ public function prepareVars() { $pathName = \UserAgentInfoPeer::getOther($this->model->{$this->columnName}); $this->vars['name'] = $this->formField->getName(); $this->vars['value'] = 'Browser: ' . $pathName->getBrowserName() . ' ' . $pathName->getBrowserVersionMajor() . ($pathName->getBrowserVersionMinor() ? '.' . $pathName->getBrowserVersionMinor() : '') . ' / OS: ' . $pathName->getOsName(); }