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


PHP Assertion::numeric方法代码示例

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


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

示例1: __construct

 /**
  * @param float $minPrice
  * @param float $maxPrice
  */
 public function __construct($minPrice = 0.0, $maxPrice = 0.0)
 {
     Assertion::numeric($minPrice);
     Assertion::numeric($maxPrice);
     $this->minPrice = (double) $minPrice;
     $this->maxPrice = (double) $maxPrice;
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:11,代码来源:PriceCondition.php

示例2: __construct

 /**
  * @param float $zValue
  * @param float $deviation
  */
 public function __construct($zValue, $deviation)
 {
     Assertion::numeric($zValue, 'Z-value was not numeric, got "%s"');
     Assertion::numeric($deviation, 'Deviation was not numeric, got "%s"');
     $this->zValue = (double) $zValue;
     $this->deviation = (double) $deviation;
 }
开发者ID:dantleech,项目名称:phpbench,代码行数:11,代码来源:ComputedResult.php

示例3: set

 public function set($tag_name, $value)
 {
     switch ($tag_name) {
         case self::LONGITUDE_TAG_NAME:
             Assertion::numeric($value);
             $this->longitude = (double) $value;
             break;
         case self::LATITUDE_TAG_NAME:
             Assertion::numeric($value);
             $this->latitude = (double) $value;
             break;
         case self::LONGITUDE_REF_TAG_NAME:
             $normalized = strtoupper($value);
             if ($normalized !== self::LONGITUDE_REF_EAST && $normalized !== self::LONGITUDE_REF_WEST) {
                 throw new \InvalidArgumentException(sprintf('Invalid longitude reference "%s" (expecting "%s" or "%s").', $value, self::LONGITUDE_REF_EAST, self::LONGITUDE_REF_WEST));
             }
             $this->longitude_ref = $value;
             break;
         case self::LATITUDE_REF_TAG_NAME:
             $normalized = strtoupper($value);
             if ($normalized !== self::LATITUDE_REF_NORTH && $normalized !== self::LATITUDE_REF_SOUTH) {
                 throw new \InvalidArgumentException(sprintf('Invalid latitude reference "%s" (expecting "%s" or "%s").', $value, self::LATITUDE_REF_NORTH, self::LATITUDE_REF_SOUTH));
             }
             $this->latitude_ref = $normalized;
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unsupported tag name "%s".', $tag_name));
     }
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:29,代码来源:GpsPosition.php

示例4: __construct

 /**
  * @param string  $name
  * @param numeric $price
  * @param integer $quantity
  * @param mixed   $id
  */
 public function __construct($name, $price, $quantity, $id = null)
 {
     Assertion::numeric($price);
     $this->setQuantity($quantity);
     $this->name = $name;
     $this->price = $price;
     $this->id = $id;
 }
开发者ID:indigophp,项目名称:simple-cart,代码行数:14,代码来源:Simple.php

示例5: __invoke

 public function __invoke($value) : ValidationResult
 {
     Assertion::numeric($value);
     $decimalValue = Decimal::fromString((string) $value);
     if ($decimalValue->comp($this->limit) === 1) {
         return new ValidationResult(new ValidationError('error.max-number', ['limit' => (string) $this->limit]));
     }
     return new ValidationResult();
 }
开发者ID:dasprid,项目名称:formidable,代码行数:9,代码来源:MaxNumberConstraint.php

示例6: __construct

 public function __construct($value)
 {
     try {
         Assertion::numeric($value);
         $this->value = $value + 0;
     } catch (AssertionInvalidArgumentException $exception) {
         throw new InvalidArgumentException($value, array('number'));
     }
 }
开发者ID:lorenzomar,项目名称:valueobject,代码行数:9,代码来源:Number.php

示例7: __construct

 public function __construct($value)
 {
     try {
         Assertion::numeric($value);
         $this->value = filter_var($value, FILTER_VALIDATE_FLOAT);
     } catch (AssertionInvalidArgumentException $exception) {
         throw new InvalidArgumentException($value, array('float'));
     }
 }
开发者ID:lorenzomar,项目名称:valueobject,代码行数:9,代码来源:Real.php

示例8: __invoke

 public function __invoke($value) : ValidationResult
 {
     Assertion::numeric($value);
     $decimalValue = Decimal::fromString((string) $value);
     $floorModulo = $this->floorModulo($decimalValue->sub($this->base), $this->step);
     if ($floorModulo->comp(DecimalConstants::zero()) !== 0) {
         return new ValidationResult(new ValidationError('error.step-number', ['lowValue' => $this->trimZeroDecimal((string) $decimalValue->sub($floorModulo)), 'highValue' => $this->trimZeroDecimal((string) $decimalValue->add($this->step)->sub($floorModulo))]));
     }
     return new ValidationResult();
 }
开发者ID:dasprid,项目名称:formidable,代码行数:10,代码来源:StepNumberConstraint.php

示例9: retrieveExchangeRateFor

 /**
  * Retrieves exchange rates from http://fixer.io
  *
  * @param Currency $currency
  */
 private function retrieveExchangeRateFor(Currency $currency)
 {
     $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/latest', ['query' => ['base' => $this->baseCurrency->getName()]]);
     Assert::same($response->getStatusCode(), 200);
     $rawExchangeRates = $response->getBody();
     $exchangeRates = json_decode($rawExchangeRates, true);
     Assert::isArray($exchangeRates);
     Assert::keyExists($exchangeRates, 'rates');
     Assert::keyExists($exchangeRates['rates'], $currency->getName());
     Assert::numeric($exchangeRates['rates'][$currency->getName()]);
     $this->exchangeRates[$currency->getName()] = $exchangeRates['rates'][$currency->getName()];
 }
开发者ID:rgeraads,项目名称:exchange-rate,代码行数:17,代码来源:FixerIoExchangeRateRetriever.php

示例10: retrieveExchangeRateFor

 /**
  * Retrieves exchange rates from http://free.currencyconverterapi.com
  *
  * @param Currency $currency
  */
 private function retrieveExchangeRateFor(Currency $currency)
 {
     $conversion = sprintf('%s_%s', $currency->getName(), $this->baseCurrency->getName());
     $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/api/v3/convert', ['query' => ['q' => $conversion]]);
     Assert::same($response->getStatusCode(), 200);
     $rawExchangeRates = $response->getBody();
     $exchangeRates = json_decode($rawExchangeRates, true);
     Assert::isArray($exchangeRates);
     Assert::keyExists($exchangeRates, 'results');
     Assert::keyExists($exchangeRates['results'], $conversion);
     Assert::keyExists($exchangeRates['results'][$conversion], 'val');
     Assert::numeric($exchangeRates['results'][$conversion]['val']);
     $this->exchangeRates[$currency->getName()] = (double) $exchangeRates['results'][$conversion]['val'];
 }
开发者ID:rgeraads,项目名称:exchange-rate,代码行数:19,代码来源:CurrencyConverterApiExchangeRateRetriever.php

示例11: withRating

 /**
  * @param float $rating
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withRating($rating)
 {
     Assertion::numeric($rating);
     Assertion::greaterOrEqualThan($rating, VideoInterface::RATING_MIN);
     Assertion::lessOrEqualThan($rating, VideoInterface::RATING_MAX);
     $instance = clone $this;
     $instance->rating = $rating;
     return $instance;
 }
开发者ID:refinery29,项目名称:sitemap,代码行数:16,代码来源:Video.php

示例12: testValidNumeric

 public function testValidNumeric()
 {
     Assertion::numeric("1");
     Assertion::numeric(1);
     Assertion::numeric(1.23);
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:6,代码来源:AssertTest.php

示例13: __construct

 /**
  * @param float $average
  */
 public function __construct($average)
 {
     Assertion::numeric($average);
     $this->average = (double) $average;
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:8,代码来源:VoteAverageCondition.php

示例14: setPrice

 /**
  * @param float $price
  */
 public function setPrice($price)
 {
     Assertion::notNull($price);
     Assertion::numeric($price);
     $this->price = $price;
 }
开发者ID:DanielVaquero,项目名称:challenges,代码行数:9,代码来源:Product.php

示例15: setDiscountedPrice

 /**
  * @param float $discountedPrice
  */
 private function setDiscountedPrice($discountedPrice)
 {
     Assertion::numeric($discountedPrice, 'Discounted price should be numeric');
     $this->discountedPrice = (double) $discountedPrice;
 }
开发者ID:matthiasnoback,项目名称:leanpub-api-client,代码行数:8,代码来源:PackageDiscount.php


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