本文整理汇总了PHP中Http::httpEngine方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::httpEngine方法的具体用法?PHP Http::httpEngine怎么用?PHP Http::httpEngine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Http
的用法示例。
在下文中一共展示了Http::httpEngine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
public static function factory($url, $options = null)
{
if (!Http::$httpEngine) {
Http::$httpEngine = function_exists('curl_init') ? 'curl' : 'php';
} elseif (Http::$httpEngine == 'curl' && !function_exists('curl_init')) {
throw new MWException(__METHOD__ . ': curl (http://php.net/curl) is not installed, but' . 'Http::$httpEngine is set to "curl"');
}
switch (Http::$httpEngine) {
case 'curl':
return new CurlHttpRequestTester($url, $options);
case 'php':
if (!wfIniGetBool('allow_url_fopen')) {
throw new MWException(__METHOD__ . ': allow_url_fopen needs to be enabled for pure PHP' . ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.');
}
return new PhpHttpRequestTester($url, $options);
default:
}
}
示例2: testCookieRequestCurl
function testCookieRequestCurl()
{
if (!self::$has_curl) {
$this->markTestIncomplete("This test requires curl.");
}
Http::$httpEngine = 'curl';
self::runCookieRequests();
}
示例3: pushToTarget
/**
* Pushes the image to the specified wiki.
*
* @since 0.5
*
* @param Title $title
* @param string $target
* @param string $token
*/
protected function pushToTarget(Title $title, $target, $token)
{
global $egPushDirectFileUploads;
$imagePage = new ImagePage($title);
$requestData = array('action' => 'upload', 'format' => 'json', 'token' => $token, 'filename' => $title->getText(), 'ignorewarnings' => '1');
if ($egPushDirectFileUploads) {
$file = $imagePage->getFile();
$be = $file->getRepo()->getBackend();
$localFile = $be->getLocalReference(array('src' => $file->getPath()));
$requestData['file'] = '@' . $localFile->getPath();
} else {
$requestData['url'] = $imagePage->getDisplayedFile()->getFullUrl();
}
$reqArgs = array('method' => 'POST', 'timeout' => 'default', 'postData' => $requestData);
if ($egPushDirectFileUploads) {
if (!function_exists('curl_init')) {
$this->dieUsage(wfMsg('push-api-err-nocurl'), 'image-push-nocurl');
} elseif (!defined('CurlHttpRequest::SUPPORTS_FILE_POSTS') || !CurlHttpRequest::SUPPORTS_FILE_POSTS) {
$this->dieUsage(wfMsg('push-api-err-nofilesupport'), 'image-push-nofilesupport');
} else {
$httpEngine = Http::$httpEngine;
Http::$httpEngine = 'curl';
$req = MWHttpRequest::factory($target, $reqArgs);
Http::$httpEngine = $httpEngine;
}
} else {
$req = PushFunctions::getHttpRequest($target, $reqArgs);
}
if (array_key_exists($target, $this->cookieJars)) {
$req->setCookieJar($this->cookieJars[$target]);
}
$status = $req->execute();
if ($status->isOK()) {
$response = $req->getContent();
$this->getResult()->addValue(null, null, FormatJson::decode($response));
Hooks::run('PushAPIAfterImagePush', array($title, $target, $token, $response));
} else {
$this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed');
}
}
示例4: factory
/**
* Generate a new request object
* @param string $url Url to use
* @param array $options (optional) extra params to pass (see Http::request())
* @param string $caller The method making this request, for profiling
* @throws MWException
* @return CurlHttpRequest|PhpHttpRequest
* @see MWHttpRequest::__construct
*/
public static function factory($url, $options = null, $caller = __METHOD__)
{
if (!Http::$httpEngine) {
Http::$httpEngine = function_exists('curl_init') ? 'curl' : 'php';
} elseif (Http::$httpEngine == 'curl' && !function_exists('curl_init')) {
throw new MWException(__METHOD__ . ': curl (http://php.net/curl) is not installed, but' . ' Http::$httpEngine is set to "curl"');
}
if (!is_array($options)) {
$options = [];
}
if (!isset($options['logger'])) {
$options['logger'] = LoggerFactory::getInstance('http');
}
switch (Http::$httpEngine) {
case 'curl':
return new CurlHttpRequest($url, $options, $caller, Profiler::instance());
case 'php':
if (!wfIniGetBool('allow_url_fopen')) {
throw new MWException(__METHOD__ . ': allow_url_fopen ' . 'needs to be enabled for pure PHP http requests to ' . 'work. If possible, curl should be used instead. See ' . 'http://php.net/curl.');
}
return new PhpHttpRequest($url, $options, $caller, Profiler::instance());
default:
throw new MWException(__METHOD__ . ': The setting of Http::$httpEngine is not valid.');
}
}
示例5: doFilesUpload
protected function doFilesUpload($aPostData, $aErrors = array())
{
global $bsgUEModulePDFCURLOptions;
$aOptions = array('timeout' => 120);
$aOptions = array_merge_recursive($aOptions, $bsgUEModulePDFCURLOptions);
$sType = $aPostData['fileType'];
if (!empty($aErrors)) {
wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Error trying to fetch files:' . "\n" . var_export($aErrors, true));
}
wfRunHooks('BSUEModulePDFUploadFilesBeforeSend', array($this, &$aPostData, $sType));
$aOptions['postData'] = $aPostData;
$vHttpEngine = Http::$httpEngine;
Http::$httpEngine = 'curl';
$sResponse = Http::post($this->aParams['soap-service-url'] . '/UploadAsset', $aOptions);
Http::$httpEngine = $vHttpEngine;
if ($sResponse != false) {
wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Successfully added "' . $sType . '"');
wfDebugLog('BS::UEModulePDF', FormatJson::encode(FormatJson::decode($sResponse), true));
} else {
wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Failed adding "' . $sType . '"');
}
}