本文整理汇总了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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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();
}
示例6: __construct
public function __construct($value)
{
try {
Assertion::numeric($value);
$this->value = $value + 0;
} catch (AssertionInvalidArgumentException $exception) {
throw new InvalidArgumentException($value, array('number'));
}
}
示例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'));
}
}
示例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();
}
示例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()];
}
示例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'];
}
示例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;
}
示例12: testValidNumeric
public function testValidNumeric()
{
Assertion::numeric("1");
Assertion::numeric(1);
Assertion::numeric(1.23);
}
示例13: __construct
/**
* @param float $average
*/
public function __construct($average)
{
Assertion::numeric($average);
$this->average = (double) $average;
}
示例14: setPrice
/**
* @param float $price
*/
public function setPrice($price)
{
Assertion::notNull($price);
Assertion::numeric($price);
$this->price = $price;
}
示例15: setDiscountedPrice
/**
* @param float $discountedPrice
*/
private function setDiscountedPrice($discountedPrice)
{
Assertion::numeric($discountedPrice, 'Discounted price should be numeric');
$this->discountedPrice = (double) $discountedPrice;
}