コード例 #1
0
ファイル: UserAgentTest.php プロジェクト: haoyanfei/zf2
 public function testUserAgentToStringReturnsHeaderFormattedString()
 {
     $this->markTestIncomplete('UserAgent needs to be completed');
     $userAgentHeader = new UserAgent();
     // @todo set some values, then test output
     $this->assertEmpty('User-Agent: xxx', $userAgentHeader->toString());
 }
コード例 #2
0
 /**
  * @param \Zend\Http\Header\UserAgent $oUserAgent
  * @param boolean $bReturnArray : if set to TRUE, this will return an array instead of an object
  * @return object|array
  */
 public function getBrowser(\Zend\Http\Header\UserAgent $oUserAgent = null, $bReturnArray = false)
 {
     if ($oUserAgent) {
         $sUserAgent = $oUserAgent->getFieldValue();
     } elseif (isset($_SERVER['HTTP_USER_AGENT'])) {
         $sUserAgent = $_SERVER['HTTP_USER_AGENT'];
     } else {
         throw new \LogicException('"HTTP_USER_AGENT" server var is undefined');
     }
     //Native function
     if ($this->getAllowsNativeGetBrowser() && $this->canUseNativeGetBrowser()) {
         return get_browser($sUserAgent, $bReturnArray);
     }
     $aReturn = array();
     foreach ($aBrowsecap = $this->getBrowscap() as $sUserAgentKey => $aUserAgentInfos) {
         if ($sUserAgentKey != '*' && !array_key_exists('parent', $aUserAgentInfos)) {
             continue;
         }
         if (preg_match('%' . $aUserAgentInfos['browser_name_regex'] . '%i', $sUserAgent)) {
             $aReturn = array('browser_name_pattern' => $sUserAgentKey) + $aUserAgentInfos;
             $iMaxDeep = 8;
             while (array_key_exists('parent', $aUserAgentInfos) && array_key_exists($sParentKey = $aUserAgentInfos['parent'], $aBrowsecap) && --$iMaxDeep > 0) {
                 $aReturn += $aUserAgentInfos = $aBrowsecap[$sParentKey];
             }
             break;
         }
     }
     return $bReturnArray ? $aReturn : (object) $aReturn;
 }