当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestUtil::request方法代码示例

本文整理汇总了PHP中RequestUtil::request方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestUtil::request方法的具体用法?PHP RequestUtil::request怎么用?PHP RequestUtil::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestUtil的用法示例。


在下文中一共展示了RequestUtil::request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCurlRequestGET

 public function testCurlRequestGET()
 {
     AppFileUtil::$neverCurl = false;
     AppFileUtil::$alwaysCurl = true;
     $url = Yii::app()->getUpdateServer() . '/installs/updates/updateCheck';
     $this->assertTrue(AppFileUtil::tryCurl($url));
     $response = RequestUtil::request(array('url' => $url, 'method' => 'GET'));
     $this->assertEquals(1, preg_match('/^\\d(\\.\\d)*$/', $response));
 }
开发者ID:shuvro35,项目名称:X2CRM,代码行数:9,代码来源:RequestUtilTest.php

示例2: translateMessage

 /**
  * Translate a message via Google Translate API.
  *
  * Helper function called by {@link updateTranslations}
  * to translate individual messages via the Google Translate API. Any text
  * between braces {} is preserved as is for variable replacement.
  *
  * @param string $message The untranslated message
  * @param string $lang The language to translate to
  * @return string The translated message
  */
 public function translateMessage($message, $lang)
 {
     $this->verbose && (print " Translating {$message} to {$lang}\n");
     $key = (require Yii::app()->basePath . '/config/googleApiKey.php');
     // Git Ignored file containing the Google API key to store. Ours is not included with public release for security reasons...
     $message = $this->addNoTranslateTags($message);
     $this->characterCount += mb_strlen($message, 'UTF-8');
     $params = array('key' => $key, 'source' => 'en', 'target' => $lang, 'q' => $message);
     $url = 'https://www.googleapis.com/language/translate/v2?' . http_build_query($params);
     $data = RequestUtil::request(array('url' => $url, 'method' => 'GET'));
     $data = json_decode($data, true);
     // Response is JSON, need to decode it to an array.
     if (isset($data['data'], $data['data']['translations'], $data['data']['translations'][0], $data['data']['translations'][0]['translatedText'])) {
         $message = $data['data']['translations'][0]['translatedText'];
         // Make sure the data structure returned is correct, then store the message as the translated version.
     } else {
         $message = '';
         // Otherwise, leave the message blank.
     }
     $message = $this->removeNoTranslateTags($message);
     $message = trim($message, '\\/');
     // Trim any harmful characters Google Translate may have moved around, like leaving a "\" at the end of the string...
     return $message;
 }
开发者ID:xl602,项目名称:X2CRM,代码行数:35,代码来源:X2TranslationBehavior.php


注:本文中的RequestUtil::request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。