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


PHP Assert::integer方法代码示例

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


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

示例1: __construct

 /**
  * @param UniquenessCheckerInterface $uniquenessChecker
  * @param int $tokenLength
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(UniquenessCheckerInterface $uniquenessChecker, $tokenLength)
 {
     Assert::integer($tokenLength, 'The value of token length has to be an integer.');
     Assert::range($tokenLength, 1, 40, 'The value of token length has to be in range between 1 to 40.');
     $this->tokenLength = $tokenLength;
     $this->uniquenessChecker = $uniquenessChecker;
 }
开发者ID:gabiudrescu,项目名称:Sylius,代码行数:13,代码来源:UniqueTokenGenerator.php

示例2: addParticipation

 /**
  * Adds a participation to the data collector.
  *
  * @param string $testIdentifier It will look like "Qp0gahJ3RAO3DJ18b0XoUQ"
  * @param int $variationIndex
  * @throws InvalidArgumentException
  */
 public function addParticipation($testIdentifier, $variationIndex)
 {
     Assert::string($testIdentifier, 'Test identifier must be a string');
     Assert::integer($variationIndex, 'Variation index must be integer');
     Assert::greaterThan($variationIndex, -1, 'Variation index must be integer >= 0');
     $this->participations[$testIdentifier] = $variationIndex;
 }
开发者ID:phpab,项目名称:phpab,代码行数:14,代码来源:Google.php

示例3: __construct

 /**
  * @param UniquenessCheckerInterface $uniquenessChecker
  * @param int $pinLength
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(UniquenessCheckerInterface $uniquenessChecker, $pinLength)
 {
     Assert::integer($pinLength, 'The value of pin length has to be an integer.');
     Assert::range($pinLength, 1, 9, 'The value of pin length has to be in range between 1 to 9.');
     $this->pinLength = $pinLength;
     $this->uniquenessChecker = $uniquenessChecker;
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:13,代码来源:UniquePinGenerator.php

示例4: getMessages

 /**
  * {@inheritdoc}
  */
 public function getMessages(ConversationInterface $conversation, $offset = 0, $limit = 20, $sortDirection = 'ASC')
 {
     Assert::integer($offset, '$offset expected an integer in Repository::getMessages(). Got: %s');
     Assert::integer($limit, '$limit expected an integer in Repository::getMessages(). Got: %s');
     Assert::oneOf(strtoupper($sortDirection), ['ASC', 'DESC'], '$sortDirection expected either ASC or DESC in Repository::getMessages(). Got: %s');
     return $this->driver->findMessages($conversation, $offset, $limit, $sortDirection);
 }
开发者ID:MHaendel,项目名称:FOSMessage,代码行数:10,代码来源:Repository.php

示例5: __construct

 /**
  * Initializes a new instance of this class.
  *
  * @param string $cookieName   The name the cookie.
  * @param int   $ttl           How long should the cookie last in browser. Default 5 years
  *                             Setting a negative number will make cookie expire after current session
  * @throws InvalidArgumentException
  */
 public function __construct($cookieName, $ttl = 157766400)
 {
     // We cannot typehint for primitive types yet so therefore we check if the cookie name is a (valid) string.
     Assert::string($cookieName, 'The cookie name is invalid.');
     Assert::notEmpty($cookieName, 'The cookie name is invalid.');
     Assert::integer($ttl, 'The cookie ttl parameter should be a integer.');
     $this->cookieName = $cookieName;
     $this->ttl = $ttl;
 }
开发者ID:phpab,项目名称:phpab,代码行数:17,代码来源:Cookie.php

示例6: __construct

 /**
  * Create a Serializer instance.
  *
  * @param int $indent The number of times the indent string is repeated.
  * @param string   $indentString    The string to indent the comment with.
  * @param bool     $indentFirstLine Whether to indent the first line.
  * @param int|null $lineLength The max length of a line or NULL to disable line wrapping.
  */
 public function __construct($indent = 0, $indentString = ' ', $indentFirstLine = true, $lineLength = null)
 {
     Assert::integer($indent);
     Assert::string($indentString);
     Assert::boolean($indentFirstLine);
     Assert::nullOrInteger($lineLength);
     $this->indent = $indent;
     $this->indentString = $indentString;
     $this->isFirstLineIndented = $indentFirstLine;
     $this->lineLength = $lineLength;
 }
开发者ID:Ocramius,项目名称:ReflectionDocBlock,代码行数:19,代码来源:Serializer.php

示例7: __construct

 /**
  * @param Key    $source
  * @param string $key
  * @param int    $bits
  * @param int    $type
  * @param array  $details
  */
 public function __construct(Key $source, $key, $bits, $type, array $details = [])
 {
     Assert::stringNotEmpty($key, __CLASS__ . '::$key expected a non empty string. Got: %s');
     Assert::integer($bits, __CLASS__ . '::$bits expected an integer. Got: %s');
     Assert::oneOf($type, [OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_EC], __CLASS__ . '::$type expected one of: %2$s. Got: %s');
     $this->source = $source;
     $this->key = $key;
     $this->bits = $bits;
     $this->type = $type;
     $this->details = $details;
 }
开发者ID:acmephp,项目名称:acmephp,代码行数:18,代码来源:ParsedKey.php

示例8: distribute

 /**
  * {@inheritdoc}
  */
 public function distribute(array $integers, $amount)
 {
     Assert::allInteger($integers);
     Assert::integer($amount);
     $total = array_sum($integers);
     $distributedAmounts = [];
     foreach ($integers as $element) {
         $distributedAmounts[] = (int) round($element * $amount / $total, 0, PHP_ROUND_HALF_DOWN);
     }
     $missingAmount = $amount - array_sum($distributedAmounts);
     for ($i = 0; $i < abs($missingAmount); $i++) {
         $distributedAmounts[$i] += $missingAmount >= 0 ? 1 : -1;
     }
     return $distributedAmounts;
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:18,代码来源:ProportionalIntegerDistributor.php

示例9: generateKeyPair

 /**
  * Generate KeyPair.
  *
  * @param int $keySize Size of the key.
  *
  * @throws KeyPairGenerationException When OpenSSL failed to generate keys.
  *
  * @return KeyPair
  */
 public function generateKeyPair($keySize = 4096)
 {
     Assert::integer($keySize, __METHOD__ . '::$keySize should be an integer. Got: %s');
     $key = openssl_pkey_new(['private_key_type' => OPENSSL_KEYTYPE_RSA, 'private_key_bits' => $keySize]);
     if (!$key) {
         throw new KeyPairGenerationException(sprintf('OpenSSL key creation failed during generation with error: %s', openssl_error_string()));
     }
     if (!openssl_pkey_export($key, $privateKey)) {
         throw new KeyPairGenerationException(sprintf('OpenSSL key export failed during generation with error: %s', openssl_error_string()));
     }
     $details = openssl_pkey_get_details($key);
     if (!is_array($details)) {
         throw new KeyPairGenerationException(sprintf('OpenSSL key parsing failed during generation with error: %s', openssl_error_string()));
     }
     return new KeyPair(new PublicKey($details['key']), new PrivateKey($privateKey));
 }
开发者ID:acmephp,项目名称:acmephp,代码行数:25,代码来源:KeyPairGenerator.php

示例10: suggestCommand

/**
 * Suggests a command based on similarity in a list of available commands.
 *
 * @param string $badCommand invalid command
 * @param array  $commands list of available commands
 * @param int    $suggestThreshold similarity threshold
 * @return string suggestion or empty string if no command is similar enough
 */
function suggestCommand($badCommand, array $commands, $suggestThreshold = 70)
{
    Assert::string($badCommand, "Bad command must be a string. Got: %s");
    Assert::integer($suggestThreshold, "Suggest threshold must be an integer. Got: %s");
    $badCommand = strtolower($badCommand);
    $bestMatch = "";
    $bestMatchPercentage = 0;
    $byRefPercentage = 0;
    foreach ($commands as $command) {
        \similar_text($badCommand, strtolower($command), $byRefPercentage);
        if ($byRefPercentage > $bestMatchPercentage) {
            $bestMatchPercentage = $byRefPercentage;
            $bestMatch = $command;
        }
    }
    return $bestMatchPercentage >= $suggestThreshold ? $bestMatch : "";
}
开发者ID:kelunik,项目名称:acme-client,代码行数:25,代码来源:functions.php

示例11: setUnitPrice

 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  */
 public function setUnitPrice($unitPrice)
 {
     Assert::integer($unitPrice, 'Unit price must be an integer.');
     $this->unitPrice = $unitPrice;
     $this->recalculateUnitsTotal();
 }
开发者ID:sylius,项目名称:order,代码行数:11,代码来源:OrderItem.php

示例12: assertFlagsValid

 private function assertFlagsValid($flags)
 {
     Assert::integer($flags, 'The option flags must be an integer. Got: %s');
     if ($flags & self::PREFER_SHORT_NAME && $flags & self::PREFER_LONG_NAME) {
         throw new InvalidArgumentException('The option flags PREFER_SHORT_NAME and PREFER_LONG_NAME cannot be combined.');
     }
 }
开发者ID:webmozart,项目名称:console,代码行数:7,代码来源:AbstractOption.php

示例13: assertFlagsValid

 private function assertFlagsValid($flags)
 {
     Assert::integer($flags, 'The argument flags must be an integer. Got: %s');
     if ($flags & self::REQUIRED && $flags & self::OPTIONAL) {
         throw new InvalidArgumentException('The argument flags REQUIRED and OPTIONAL cannot be combined.');
     }
     if ($flags & self::STRING) {
         if ($flags & self::BOOLEAN) {
             throw new InvalidArgumentException('The argument flags STRING and BOOLEAN cannot be combined.');
         }
         if ($flags & self::INTEGER) {
             throw new InvalidArgumentException('The argument flags STRING and INTEGER cannot be combined.');
         }
         if ($flags & self::FLOAT) {
             throw new InvalidArgumentException('The argument flags STRING and FLOAT cannot be combined.');
         }
     } elseif ($flags & self::BOOLEAN) {
         if ($flags & self::INTEGER) {
             throw new InvalidArgumentException('The argument flags BOOLEAN and INTEGER cannot be combined.');
         }
         if ($flags & self::FLOAT) {
             throw new InvalidArgumentException('The argument flags BOOLEAN and FLOAT cannot be combined.');
         }
     } elseif ($flags & self::INTEGER) {
         if ($flags & self::FLOAT) {
             throw new InvalidArgumentException('The argument flags INTEGER and FLOAT cannot be combined.');
         }
     }
 }
开发者ID:webmozart,项目名称:console,代码行数:29,代码来源:Argument.php

示例14: setNumber

 /**
  * Set number
  *
  * @param integer $number
  * @return Course
  */
 public function setNumber($number)
 {
     Assert::integer($number);
     $this->number = $number;
     $this->refreshKey();
     return $this;
 }
开发者ID:winkutc,项目名称:server,代码行数:13,代码来源:Course.php

示例15: requestCertificate

 /**
  * {@inheritdoc}
  */
 public function requestCertificate($domain, CertificateRequest $csr, $timeout = 180)
 {
     Assert::stringNotEmpty($domain, 'requestCertificate::$domain expected a non-empty string. Got: %s');
     Assert::integer($timeout, 'requestCertificate::$timeout expected an integer. Got: %s');
     $humanText = ['-----BEGIN CERTIFICATE REQUEST-----', '-----END CERTIFICATE REQUEST-----'];
     $csrContent = $this->csrSigner->signCertificateRequest($csr);
     $csrContent = trim(str_replace($humanText, '', $csrContent));
     $csrContent = trim($this->httpClient->getBase64Encoder()->encode(base64_decode($csrContent)));
     $response = $this->requestResource('POST', ResourcesDirectory::NEW_CERTIFICATE, ['resource' => ResourcesDirectory::NEW_CERTIFICATE, 'csr' => $csrContent], false);
     // If the CA has not yet issued the certificate, the body of this response will be empty
     if (strlen(trim($response)) < 10) {
         // 10 to avoid false results
         $location = $this->httpClient->getLastLocation();
         // Waiting loop
         $endTime = time() + $timeout;
         while (time() <= $endTime) {
             $response = $this->httpClient->unsignedRequest('GET', $location, null, false);
             if (200 === $this->httpClient->getLastCode()) {
                 break;
             }
             if (202 !== $this->httpClient->getLastCode()) {
                 throw new CertificateRequestFailedException($response);
             }
             sleep(1);
         }
         if (202 === $this->httpClient->getLastCode()) {
             throw new CertificateRequestTimedOutException($response);
         }
     }
     // Find issuers certificate
     $links = $this->httpClient->getLastLinks();
     $certificatesChain = null;
     foreach ($links as $link) {
         if (!isset($link['rel']) || 'up' !== $link['rel']) {
             continue;
         }
         $location = trim($link[0], '<>');
         $certificate = $this->httpClient->unsignedRequest('GET', $location, null, false);
         if (strlen(trim($certificate)) > 10) {
             $pem = chunk_split(base64_encode($certificate), 64, "\n");
             $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n";
             $certificatesChain = new Certificate($pem, $certificatesChain);
         }
     }
     // Domain certificate
     $pem = chunk_split(base64_encode($response), 64, "\n");
     $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n";
     return new CertificateResponse($csr, new Certificate($pem, $certificatesChain));
 }
开发者ID:acmephp,项目名称:core,代码行数:52,代码来源:AcmeClient.php


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