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


PHP Checker::argNat方法代码示例

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


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

示例1: chunkedUploadContinue

 /**
  * Append another chunk data to a previously-started chunked upload session.
  *
  * @param string $uploadId
  *     The unique identifier for the chunked upload session.  This is obtained via
  *     {@link chunkedUploadStart}.
  *
  * @param int $byteOffset
  *     The number of bytes you think you've already uploaded to the given chunked upload
  *     session.  The server will append the new chunk of data after that point.
  *
  * @param string $data
  *     The data to append to the existing chunked upload session.
  *
  * @return int|bool
  *     If <code>false</code>, it means the server didn't know about the given
  *     <code>$uploadId</code>.  This may be because the chunked upload session has expired
  *     (they last around 24 hours).
  *     If <code>true</code>, the chunk was successfully uploaded.  If an integer, it means
  *     you and the server don't agree on the current <code>$byteOffset</code>.  The returned
  *     integer is the server's internal byte offset for the chunked upload session.  You need
  *     to adjust your input to match.
  *
  * @throws Exception
  */
 function chunkedUploadContinue($uploadId, $byteOffset, $data)
 {
     Checker::argStringNonEmpty("uploadId", $uploadId);
     Checker::argNat("byteOffset", $byteOffset);
     Checker::argString("data", $data);
     $response = $this->_chunkedUpload(array("upload_id" => $uploadId, "offset" => $byteOffset), $data);
     if ($response->statusCode === 404) {
         // The server doesn't know our upload ID.  Maybe it expired?
         return false;
     }
     $correction = self::_chunkedUploadCheckForOffsetCorrection($response);
     if ($correction !== null) {
         list($correctedUploadId, $correctedByteOffset) = $correction;
         if ($correctedUploadId !== $uploadId) {
             throw new Exception_BadResponse("Corrective 400 upload_id mismatch: us=" . self::q($uploadId) . " server=" . self::q($correctedUploadId));
         }
         if ($correctedByteOffset === $byteOffset) {
             throw new Exception_BadResponse("Corrective 400 offset is the same as ours: {$byteOffset}");
         }
         return $correctedByteOffset;
     }
     if ($response->statusCode !== 200) {
         throw RequestUtil::unexpectedStatus($response);
     }
     list($retUploadId, $retByteOffset) = self::_chunkedUploadParse200Response($response->body);
     $nextByteOffset = $byteOffset + strlen($data);
     if ($uploadId !== $retUploadId) {
         throw new Exception_BadResponse("upload_id mismatch: us=" . self::q($uploadId) . ", server=" . self::q($uploadId));
     }
     if ($nextByteOffset !== $retByteOffset) {
         throw new Exception_BadResponse("next-offset mismatch: us={$nextByteOffset}, server={$retByteOffset}");
     }
     return true;
 }
开发者ID:themexpand,项目名称:xpand-buddy,代码行数:59,代码来源:Client.php

示例2: runWithRetry

 /**
  * @param int $maxRetries
  *    The number of times to retry it the action if it fails with one of the transient
  *    API errors.  A value of 1 means we'll try the action once and if it fails, we
  *    will retry once.
  *
  * @param callable $action
  *    The the action you want to retry.
  *
  * @return mixed
  *    Whatever is returned by the $action callable.
  */
 static function runWithRetry($maxRetries, $action)
 {
     Checker::argNat("maxRetries", $maxRetries);
     $retryDelay = 1;
     $numRetries = 0;
     while (true) {
         try {
             return $action();
         } catch (Exception_NetworkIO $ex) {
             $savedEx = $ex;
         } catch (Exception_ServerError $ex) {
             $savedEx = $ex;
         } catch (Exception_RetryLater $ex) {
             $savedEx = $ex;
         }
         // We maxed out our retries.  Propagate the last exception we got.
         if ($numRetries >= $maxRetries) {
             throw $savedEx;
         }
         $numRetries++;
         sleep($retryDelay);
         $retryDelay *= 2;
         // Exponential back-off.
     }
     throw new \RuntimeException("unreachable");
 }
开发者ID:AgilData,项目名称:WordPress-Skeleton,代码行数:38,代码来源:RequestUtil.php


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