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


PHP MWHttpRequest::canMakeRequests方法代码示例

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


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

示例1: request

 /**
  * The general method for handling the communication with the service.
  */
 public function request($resourceName, $getParams = [], $postData = [], $extraRequestOptions = [])
 {
     // Crash if we cannot make HTTP requests.
     \Wikia\Util\Assert::true(\MWHttpRequest::canMakeRequests());
     // Add client_id and client_secret to the GET data.
     $getParams['client_id'] = $this->clientId;
     $getParams['client_secret'] = $this->clientSecret;
     // Request URI pre-processing.
     $uri = "{$this->baseUri}{$resourceName}?" . http_build_query($getParams);
     // Request options pre-processing.
     $options = ['method' => 'GET', 'timeout' => 5, 'postData' => $postData, 'noProxy' => true, 'followRedirects' => false, 'returnInstance' => true, 'internalRequest' => true];
     $options = array_merge($options, $extraRequestOptions);
     /*
      * MediaWiki's MWHttpRequest class heavily relies on Messaging API
      * (wfMessage()) which happens to rely on the value of $wgLang.
      * $wgLang is set after $wgUser. On per-request authentication with
      * an access token we use MWHttpRequest before wgUser is created so
      * we need $wgLang to be present. With GlobalStateWrapper we can set
      * the global variable in the local, function's scope, so it is the
      * same as the already existing $wgContLang.
      */
     global $wgContLang;
     $wrapper = new GlobalStateWrapper(['wgLang' => $wgContLang]);
     // Request execution.
     /** @var \MWHttpRequest $request */
     $request = $wrapper->wrap(function () use($options, $uri) {
         return \Http::request($options['method'], $uri, $options);
     });
     $this->status = $request->status;
     $output = json_decode($request->getContent());
     if (!$output) {
         throw new ClientException('Invalid response.');
     }
     return $output;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:38,代码来源:Client.class.php

示例2: subscribeToMediaWikiAnnounce

 /**
  * @param $s Status
  */
 private function subscribeToMediaWikiAnnounce(Status $s)
 {
     $params = array('email' => $this->getVar('_AdminEmail'), 'language' => 'en', 'digest' => 0);
     // Mailman doesn't support as many languages as we do, so check to make
     // sure their selected language is available
     $myLang = $this->getVar('_UserLang');
     if (in_array($myLang, $this->mediaWikiAnnounceLanguages)) {
         $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang;
         // rewrite to Mailman's pt_BR
         $params['language'] = $myLang;
     }
     if (MWHttpRequest::canMakeRequests()) {
         $res = MWHttpRequest::factory($this->mediaWikiAnnounceUrl, array('method' => 'POST', 'postData' => $params))->execute();
         if (!$res->isOK()) {
             $s->warning('config-install-subscribe-fail', $res->getMessage());
         }
     } else {
         $s->warning('config-install-subscribe-notpossible');
     }
 }
开发者ID:laiello,项目名称:media-wiki-law,代码行数:23,代码来源:Installer.php


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