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


PHP Middleware::httpErrors方法代码示例

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


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

示例1: create

 /**
  * Creates a default handler stack that can be used by clients.
  *
  * The returned handler will wrap the provided handler or use the most
  * appropriate default handler for you system. The returned HandlerStack has
  * support for cookies, redirects, HTTP error exceptions, and preparing a body
  * before sending.
  *
  * The returned handler stack can be passed to a client in the "handler"
  * option.
  *
  * @param callable $handler HTTP handler function to use with the stack. If no
  *                          handler is provided, the best handler for your
  *                          system will be utilized.
  *
  * @return HandlerStack
  */
 public static function create(callable $handler = null)
 {
     $stack = new self($handler ?: choose_handler());
     $stack->push(Middleware::httpErrors(), 'http_errors');
     $stack->push(Middleware::redirect(), 'allow_redirects');
     $stack->push(Middleware::cookies(), 'cookies');
     $stack->push(Middleware::prepareBody(), 'prepare_body');
     return $stack;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:HandlerStack.php

示例2: testLogsRequestsAndErrors

 public function testLogsRequestsAndErrors()
 {
     $h = new MockHandler([new Response(404)]);
     $stack = new HandlerStack($h);
     $logger = new Logger();
     $formatter = new MessageFormatter('{code} {error}');
     $stack->push(Middleware::log($logger, $formatter));
     $stack->push(Middleware::httpErrors());
     $comp = $stack->resolve();
     $p = $comp(new Request('PUT', 'http://www.google.com'), ['http_errors' => true]);
     $p->wait(false);
     $this->assertContains('PUT http://www.google.com', $logger->output);
     $this->assertContains('404 Not Found', $logger->output);
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:14,代码来源:MiddlewareTest.php

示例3: __construct

 /**
  * Construct a FamilySearch Client.
  *
  * @param array $options A keyed array of configuration options for the client. Available options:
  * 
  * * `clientId` - Required for authentication.
  * * `redirectURI` - Required for authentication.
  * * `accessToken` - If the access token is set then the `clientId` and `redirectURI` are not needed.
  * * `environment` - `production`, `beta`, or `sandbox`; defaults to `sandbox`.
  * * `userAgent` - A string which will be prepended to the default user agent string.
  * * `pendingModifications` - An array of pending modifications that should be enabled.
  * * `logger` - A `Psr\Log\LoggerInterface`. A logger can also be registered via the `setLogger()` method but passing it in as an option during instantiation ensures that the logger will see all client events.
  * * `middleware` - An array of [Guzzle Middleware](http://docs.guzzlephp.org/en/latest/handlers-and-middleware.html#middleware).
  * * `httpExceptions` - When `true`, the client will throw a `Gedcomx\Rs\Client\Exception\GedcomxApplicationException` when a 400 or 500 level HTTP response is received. 
  * * `throttling` - When `true`, the client will automatically handled throttled responses.
  */
 public function __construct($options = array())
 {
     if (isset($options['redirectURI'])) {
         $this->redirectURI = $options['redirectURI'];
     }
     if (isset($options['clientId'])) {
         $this->clientId = $options['clientId'];
     }
     // Set the proper homeURI based on the environment.
     // Default to sandbox.
     $environment = '';
     $baseURI = '';
     if (isset($options['environment'])) {
         $environment = $options['environment'];
     }
     switch ($environment) {
         case 'production':
             $baseURI = 'https://familysearch.org';
             break;
         case 'beta':
             $baseURI = 'https://beta.familysearch.org';
             break;
         default:
             $baseURI = 'https://sandbox.familysearch.org';
             break;
     }
     $this->homeURI = $baseURI . '/platform/collection';
     // Middleware
     $this->stack = new HandlerStack();
     $this->stack->setHandler(new CurlHandler());
     $this->stack->push(Middleware::httpErrors());
     $this->stack->push(Middleware::redirect());
     // Pending modifications
     if (isset($options['pendingModifications']) && is_array($options['pendingModifications']) && count($options['pendingModifications']) > 0) {
         $experiments = join(",", $options['pendingModifications']);
         $this->stack->push(Middleware::mapRequest(function (RequestInterface $request) use($experiments) {
             return $request->withHeader('X-FS-Feature-Tag', $experiments);
         }));
     }
     // Throttling
     if (isset($options['throttling']) && $options['throttling'] === true) {
         $this->stack->push(ThrottlingMiddleware::middleware());
     }
     // Set user agent string
     $userAgent = 'gedcomx-php/1.1.1 ' . \GuzzleHttp\default_user_agent();
     if (isset($options['userAgent'])) {
         $userAgent = $options['userAgent'] . ' ' . $userAgent;
     }
     // Custom middleware
     if (isset($options['middleware']) && is_array($options['middleware'])) {
         foreach ($options['middleware'] as $middleware) {
             $this->stack->push($middleware);
         }
     }
     // This goes last so that it sees the final request and response
     if (isset($options['logger'])) {
         $this->setLogger($options['logger']);
     }
     $clientOptions = ['handler' => $this->stack, 'base_uri' => $baseURI, 'headers' => ['User-Agent' => $userAgent]];
     // Throw exceptions
     if (isset($options['httpExceptions']) && $options['httpExceptions'] === true) {
         $clientOptions['http_errors'] = true;
     } else {
         $clientOptions['http_errors'] = false;
     }
     // Create client
     $this->client = new Client($clientOptions);
     $this->stateFactory = new FamilyTreeStateFactory();
     $this->createHomeState();
     $this->createTreeState();
     if (isset($options['accessToken'])) {
         $this->treeState->authenticateWithAccessToken($options['accessToken']);
     }
 }
开发者ID:BRGWeb,项目名称:gedcomx-php,代码行数:90,代码来源:FamilySearchClient.php


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