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


PHP Promise\promise_for函数代码示例

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


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

示例1: __invoke

 public function __invoke(CommandInterface $command, RequestInterface $request)
 {
     if (!$this->queue) {
         $last = $this->lastCommand ? ' The last command sent was ' . $this->lastCommand->getName() . '.' : '';
         throw new \RuntimeException('Mock queue is empty. Trying to send a ' . $command->getName() . ' command failed.' . $last);
     }
     $this->lastCommand = $command;
     $this->lastRequest = $request;
     $result = array_shift($this->queue);
     if (is_callable($result)) {
         $result = $result($command, $request);
     }
     if ($result instanceof \Exception) {
         $result = new RejectedPromise($result);
     } else {
         // Add an effective URI and statusCode if not present.
         $meta = $result['@metadata'];
         if (!isset($meta['effectiveUri'])) {
             $meta['effectiveUri'] = (string) $request->getUri();
         }
         if (!isset($meta['statusCode'])) {
             $meta['statusCode'] = 200;
         }
         $result['@metadata'] = $meta;
         $result = Promise\promise_for($result);
     }
     $result->then($this->onFulfilled, $this->onRejected);
     return $result;
 }
开发者ID:AWSRandall,项目名称:aws-sdk-php,代码行数:29,代码来源:MockHandler.php

示例2: __invoke

 /**
  * Calls the simpler HTTP specific handler and wraps the returned promise
  * with AWS specific values (e.g., a result object or AWS exception).
  *
  * @param CommandInterface $command Command being executed.
  * @param RequestInterface $request Request to send.
  *
  * @return Promise\PromiseInterface
  */
 public function __invoke(CommandInterface $command, RequestInterface $request)
 {
     $fn = $this->httpHandler;
     return Promise\promise_for($fn($request, $command['@http'] ?: []))->then(function (ResponseInterface $res) use($command, $request) {
         return $this->parseResponse($command, $request, $res);
     }, function ($err) use($request, $command) {
         if (is_array($err)) {
             $exception = $this->parseError($err, $request, $command);
             return new Promise\RejectedPromise($exception);
         }
         return new Promise\RejectedPromise($err);
     });
 }
开发者ID:Cinemacloud,项目名称:angular-moviemasher,代码行数:22,代码来源:WrappedHttpHandler.php

示例3: getCredentials

 /**
  * This function creates an AWS credential provider
  *
  * @return callable
  */
 private function getCredentials()
 {
     return function () {
         $config = $this->getConfig();
         $key = $config["securefiles_s3_key"];
         $secret = $config["securefiles_s3_secret"];
         if ($key && $secret) {
             return Promise\promise_for(new Credentials($key, $secret));
         }
         $msg = 'Could not retrieve credentials';
         return new RejectedPromise(new CredentialsException($msg));
     };
 }
开发者ID:ginkgostreet,项目名称:com.ginkgostreet.securefiles,代码行数:18,代码来源:AmazonS3.php

示例4: each

 /**
  * Runs a paginator asynchronously and uses a callback to handle results.
  *
  * The callback should have the signature: function (Aws\Result $result).
  * A non-null return value from the callback will be yielded by the
  * promise. This means that you can return promises from the callback that
  * will need to be resolved before continuing iteration over the remaining
  * items, essentially merging in other promises to the iteration. The last
  * non-null value returned by the callback will be the result that fulfills
  * the promise to any downstream promises.
  *
  * @param callable $handleResult Callback for handling each page of results.
  *                               The callback accepts the result that was
  *                               yielded as a single argument. If the
  *                               callback returns a promise, the promise
  *                               will be merged into the coroutine.
  *
  * @return Promise\Promise
  */
 public function each(callable $handleResult)
 {
     return Promise\coroutine(function () use($handleResult) {
         $nextToken = null;
         do {
             $command = $this->createNextCommand($this->args, $nextToken);
             $result = (yield $this->client->executeAsync($command));
             $nextToken = $this->determineNextToken($result);
             $retVal = $handleResult($result);
             if ($retVal !== null) {
                 (yield Promise\promise_for($retVal));
             }
         } while ($nextToken);
     });
 }
开发者ID:xgin,项目名称:aws-sdk-php,代码行数:34,代码来源:ResultPaginator.php

示例5: __invoke

 /**
  * Calls the simpler HTTP specific handler and wraps the returned promise
  * with AWS specific values (e.g., a result object or AWS exception).
  *
  * @param CommandInterface $command Command being executed.
  * @param RequestInterface $request Request to send.
  *
  * @return Promise\PromiseInterface
  */
 public function __invoke(CommandInterface $command, RequestInterface $request)
 {
     $fn = $this->httpHandler;
     $options = $command['@http'] ?: [];
     $stats = [];
     if ($this->collectStats) {
         $options['http_stats_receiver'] = static function (array $transferStats) use(&$stats) {
             $stats = $transferStats;
         };
     } elseif (isset($options['http_stats_receiver'])) {
         throw new \InvalidArgumentException('Providing a custom HTTP stats' . ' receiver to Aws\\WrappedHttpHandler is not supported.');
     }
     return Promise\promise_for($fn($request, $options))->then(function (ResponseInterface $res) use($command, $request, &$stats) {
         return $this->parseResponse($command, $request, $res, $stats);
     }, function ($err) use($request, $command, &$stats) {
         if (is_array($err)) {
             $err = $this->parseError($err, $request, $command, $stats);
         }
         return new Promise\RejectedPromise($err);
     });
 }
开发者ID:Air-Craft,项目名称:air-craft-www,代码行数:30,代码来源:WrappedHttpHandler.php

示例6: 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

示例7: determineBucketRegionAsync

 public function determineBucketRegionAsync($bucketName)
 {
     if ($cached = $this->cache->get($this->getCacheKey($bucketName))) {
         return Promise\promise_for($cached);
     }
     return $this->lookupBucketRegion($bucketName)->then(function ($region) use($bucketName) {
         $this->cache->set($this->getCacheKey($bucketName), $region);
         return $region;
     });
 }
开发者ID:Afrozaar,项目名称:wp-api-v2-afrozaar-extras,代码行数:10,代码来源:S3MultiRegionClient.php

示例8: 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

示例9: ini

 /**
  * Credentials provider that creates credentials using an ini file stored
  * in the current user's home directory.
  *
  * @param string|null $profile  Profile to use. If not specified will use
  *                              the "default" profile.
  * @param string|null $filename If provided, uses a custom filename rather
  *                              than looking in the home directory for the
  *
  * @return callable
  */
 public static function ini($profile = null, $filename = null)
 {
     $filename = $filename ?: self::getHomeDir() . '/.aws/credentials';
     $profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
     return function () use($profile, $filename) {
         if (!is_readable($filename)) {
             return self::reject("Cannot read credentials from {$filename}");
         }
         $data = parse_ini_file($filename, true);
         if ($data === false) {
             return self::reject("Invalid credentials file: {$filename}");
         }
         if (!isset($data[$profile])) {
             return self::reject("'{$profile}' not found in credentials file");
         }
         if (!isset($data[$profile]['aws_access_key_id']) || !isset($data[$profile]['aws_secret_access_key'])) {
             return self::reject("No credentials present in INI profile " . "'{$profile}' ({$filename})");
         }
         return Promise\promise_for(new Credentials($data[$profile]['aws_access_key_id'], $data[$profile]['aws_secret_access_key'], isset($data[$profile]['aws_security_token']) ? $data[$profile]['aws_security_token'] : null));
     };
 }
开发者ID:matt-schuh,项目名称:westminster-drops-8,代码行数:32,代码来源:CredentialProvider.php

示例10: ini

 /**
  * todo ini 文件加载
  *
  * @param null $profile
  * @param null $filename
  *
  * @return \Closure
  */
 public static function ini($profile = null, $filename = null)
 {
     $filename = $filename ?: './.cloudatlas/credentials';
     $profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
     $credentialConcrete = static::getCredentialConcrete();
     return function () use($profile, $filename, $credentialConcrete) {
         if (!is_readable($filename)) {
             return self::reject("Cannot read credentials from {$filename}");
         }
         $data = parse_ini_file($filename, true);
         if ($data === false) {
             return self::reject("Invalid credentials file: {$filename}");
         }
         if (!isset($data[$profile])) {
             return self::reject("'{$profile}' not found in credentials file.");
         }
         if (!isset($data[$profile][constant(static::ENV_KEY)]) || !isset($data[$profile][constant(static::ENV_SECRET)])) {
             return self::reject("No credentials present in INI profile " . "'{$profile}' ({$filename})");
         }
         return Promise\promise_for(new $credentialConcrete($data[$profile][constant(static::ENV_KEY)], $data[$profile][constant(static::ENV_SECRET)]));
     };
 }
开发者ID:abrahamgreyson,项目名称:cloudatlas,代码行数:30,代码来源:AbstractCredentialProvider.php


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