本文整理汇总了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));
}
示例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;
}