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


PHP Promise\rejection_for函数代码示例

本文整理汇总了PHP中GuzzleHttp\Promise\rejection_for函数的典型用法代码示例。如果您正苦于以下问题:PHP rejection_for函数的具体用法?PHP rejection_for怎么用?PHP rejection_for使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: send

 /**
  * Perform a request and return a promise object (an object
  * implementing then method)
  *
  * @param RequestInterface $request
  * @param array $options
  *
  * @return object|P\PromiseInterface
  */
 public function send(RequestInterface $request, array $options = [])
 {
     $request = $this->preRequest($request, $options);
     $promise = $this->transport->exec($request)->then(function (ResponseInterface $response) use($request, $options, &$promise) {
         $event = $this->responseEvent($request, $response, $options);
         $response = $event->getResponse();
         if (!$this->isResponseOK($response)) {
             return P\rejection_for($event);
         }
         return $response;
     })->then(null, function (ResponseEvent $event) use($options) {
         // options is passed by reference. Use array_merge to ensure
         // opts is a copy and not a reference
         $opts = array_merge([], $options);
         $naReq = $this->getNextRequest($event, $opts);
         if ($naReq) {
             $options['exceptions'] = false;
             return $this->send($naReq, $opts);
         }
         $response = $event->getResponse();
         if ($options['exceptions']) {
             throw new BadApiResponseException($response, $response->getStatusCode(), $response->getReasonPhrase());
         }
         return $response;
     });
     // Add in shutdown queue
     $this->queue->add(function () use($promise) {
         $promise->wait(false);
     });
     return $promise;
 }
开发者ID:alekitto,项目名称:api-connector-bundle,代码行数:40,代码来源:ApiRequestManager.php

示例2: createPromise

 /**
  * Returns a promise that will clean up any references when it completes.
  *
  * @return PromiseInterface
  */
 private function createPromise()
 {
     // Create the promise
     $promise = call_user_func($this->promiseCreator, $this);
     $this->promiseCreator = null;
     // Cleans up the promise state and references.
     $cleanup = function () {
         $this->before = $this->client = $this->queue = null;
     };
     // When done, ensure cleanup and that any remaining are processed.
     return $promise->then(function () use($cleanup) {
         return Promise\promise_for($this->flushQueue())->then($cleanup);
     }, function ($reason) use($cleanup) {
         $cleanup();
         return Promise\rejection_for($reason);
     });
 }
开发者ID:Cinemacloud,项目名称:angular-moviemasher,代码行数:22,代码来源:BatchDelete.php

示例3: transfer

 /**
  * Transfers the given request and applies request options.
  *
  * The URI of the request is not modified and the request options are used
  * as-is without merging in default options.
  *
  * @param RequestInterface $request
  * @param array            $options
  *
  * @return Promise\PromiseInterface
  */
 private function transfer(RequestInterface $request, array $options)
 {
     // save_to -> sink
     if (isset($options['save_to'])) {
         $options['sink'] = $options['save_to'];
         unset($options['save_to']);
     }
     // exceptions -> http_errors
     if (isset($options['exceptions'])) {
         $options['http_errors'] = $options['exceptions'];
         unset($options['exceptions']);
     }
     $request = $this->applyOptions($request, $options);
     $handler = $options['handler'];
     try {
         return Promise\promise_for($handler($request, $options));
     } catch (\Exception $e) {
         return Promise\rejection_for($e);
     }
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:31,代码来源:Client.php

示例4: history

 /**
  * Tracks command and request history using a history container.
  *
  * This is useful for testing.
  *
  * @param History $history History container to store entries.
  *
  * @return callable
  */
 public static function history(History $history)
 {
     return function (callable $handler) use($history) {
         return function (CommandInterface $command, RequestInterface $request = null) use($handler, $history) {
             $ticket = $history->start($command, $request);
             return $handler($command, $request)->then(function ($result) use($history, $ticket) {
                 $history->finish($ticket, $result);
                 return $result;
             }, function ($reason) use($history, $ticket) {
                 $history->finish($ticket, $reason);
                 return Promise\rejection_for($reason);
             });
         };
     };
 }
开发者ID:abdala,项目名称:generic-api-client,代码行数:24,代码来源:Middleware.php

示例5: createDownloadPromise

 private function createDownloadPromise()
 {
     // Prepare args for ListObjects.
     $listArgs = $this->getS3Args($this->source['path']);
     if (isset($listArgs['Key'])) {
         $listArgs['Prefix'] = $listArgs['Key'] . '/';
         unset($listArgs['Key']);
     }
     // Get the Paginator for ListObjects
     $objects = $this->client->getPaginator('ListObjects', $listArgs);
     // Asynchronously execute the paginator, building command pools to
     // download the objects.
     return $objects->each(function (ResultInterface $result) use($listArgs) {
         $commands = [];
         $prefix = isset($listArgs['Prefix']) ? $listArgs['Prefix'] : null;
         foreach ($result->search('Contents[].Key') as $key) {
             // Skip files on S3 that just mark the existence of a folder.
             if (substr($key, -1, 1) === '/') {
                 continue;
             }
             // Prepare the sink.
             $localKey = $key;
             if ($prefix && strpos($localKey, $prefix) === 0) {
                 $localKey = substr($key, strlen($prefix));
             }
             $sink = $this->destination['path'] . '/' . $localKey;
             // Create the directory if needed.
             $dir = dirname($sink);
             if (!is_dir($dir) && !mkdir($dir, 0777, true)) {
                 return Promise\rejection_for(new \RuntimeException("Could not create dir: {$dir}"));
             }
             // Create the command.
             $commands[] = $this->client->getCommand('GetObject', ['Bucket' => $listArgs['Bucket'], 'Key' => $key, '@http' => ['sink' => $sink]]);
         }
         // Create a GetObject command pool and return the promise.
         return (new Aws\CommandPool($this->client, $commands, ['concurrency' => $this->concurrency, 'before' => $this->before, 'rejected' => function ($reason, $idx, Promise\PromiseInterface $p) {
             $p->reject($reason);
         }]))->promise();
     });
 }
开发者ID:geryjuhasz,项目名称:aws-sdk-php,代码行数:40,代码来源:Transfer.php

示例6: timer

 public static function timer()
 {
     return function (callable $handler) {
         return function (CommandInterface $command, RequestInterface $request = null) use($handler) {
             $start = microtime(true);
             return $handler($command, $request)->then(function (ResultInterface $res) use($start) {
                 if (!isset($res['@metadata'])) {
                     $res['@metadata'] = [];
                 }
                 if (!isset($res['@metadata']['transferStats'])) {
                     $res['@metadata']['transferStats'] = [];
                 }
                 $res['@metadata']['transferStats']['total_time'] = microtime(true) - $start;
                 return $res;
             }, function ($err) use($start) {
                 if ($err instanceof AwsException) {
                     $err->setTransferInfo(['total_time' => microtime(true) - $start] + $err->getTransferInfo());
                 }
                 return Promise\rejection_for($err);
             });
         };
     };
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:23,代码来源:Middleware.php

示例7: onFailure

 /**
  * Returns a function which is handled when a request was rejected.
  *
  * @param RequestInterface $request
  *
  * @return Closure
  */
 protected function onFailure(RequestInterface $request)
 {
     return function ($reason) use($request) {
         // Only log a rejected requests if it hasn't already been logged
         if (!$this->logRequests) {
             $this->log($request, null, $reason);
         }
         return Promise\rejection_for($reason);
     };
 }
开发者ID:rtheunissen,项目名称:guzzle-log-middleware,代码行数:17,代码来源:Logger.php


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