public function match($value) { switch ($this->option) { case ReportConditionalStyleOption::ANY: return true; case ReportConditionalStyleOption::TEXT_CONTAINS: return stristr($value, $this->data); case ReportConditionalStyleOption::TEXT_NOT_CONTAINS: return !stristr($value, $this->data); case ReportConditionalStyleOption::TEXT_EXACT: return $this->data === $value; case ReportConditionalStyleOption::TEXT_MATCH: return $this->data == $value; case ReportConditionalStyleOption::GREATER_THAN: return $value > $this->data; case ReportConditionalStyleOption::GREATER_OR_EQUAL: return $value >= $this->data; case ReportConditionalStyleOption::LESS_THAN: return $value < $this->data; case ReportConditionalStyleOption::LESS_OR_EQUAL: return $value <= $this->data; case ReportConditionalStyleOption::EQUAL: return $this->data == $value; case ReportConditionalStyleOption::NOT_EQUAL: return $this->data != $value; case ReportConditionalStyleOption::BETWEEN: return Numbers::between($value, $this->data->from, $this->data->to); case ReportConditionalStyleOption::NOT_BETWEEN: return !Numbers::between($value, $this->data->from, $this->data->to); case ReportConditionalStyleOption::NO_VALUE: return $value === '' || $value === null; } return false; }
public function testBetween() { $this->assertTrue(Numbers::between(2, 1, 3)); $this->assertTrue(Numbers::between(2, 1, 2)); $this->assertFalse(Numbers::between(3, 1, 2)); $this->assertFalse(Numbers::between(3, 1, 2, true)); $this->assertFalse(Numbers::between(2, 1, 2, false)); }
public static function getType($fid) { $parts = explode(':', $fid); if (strlen($fid) < 32 || !Numbers::between(count($parts), 4, 5)) { return null; } if ($parts[0] != 'FID') { return null; } $type = $subType = $parts[1]; if (count($parts) === 5) { $subType = $parts[2]; } $reflection = new \ReflectionClass('\\Fortifi\\FortifiApi\\Foundation\\Fids\\FidTypes'); $const = $type . '_' . $subType; if ($reflection->hasConstant($const)) { return $reflection->getConstant($const); } return null; }
/** * Number format with suffix, for making large numbers human readable * * @param float $number * @param bool $digital Use digital units of measurement * * @return string A formatted version of number. * * @deprecated */ function nhumanize($number, $digital = false) { return \Packaged\Helpers\Numbers::humanize($number, $digital); }
public function runValidator($tag, $property, $value, $options) { $msg = null; switch (strtolower($tag)) { case 'required': if (empty($value)) { $msg = "is required"; } break; case 'bool': if (!is_bool($value)) { $msg = "is not a valid bool"; } break; case 'int': if (!is_integer($value)) { $msg = "is not a valid integer"; } break; case 'float': if (!is_float($value)) { $msg = "is not a valid float"; } break; case 'scalar': if (!is_scalar($value)) { $msg = "is not a valid float"; } break; case 'length': list($low, $high) = explode(' ', $options, 2); if (!Numbers::between(strlen($value), (int) $low, (int) $high)) { $msg = "is not between " . (int) $low . ' and ' . (int) $high . ' characters'; } break; case 'between': list($low, $high) = explode(' ', $options, 2); if (!Numbers::between((int) $value, (int) $low, (int) $high)) { $msg = "is not between " . (int) $low . ' and ' . (int) $high; } break; case 'email': if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $msg = "is not a valid email address"; } else { if (stristr($options, 'dns')) { list(, $host) = explode('@', $value, 2); if (!checkdnsrr($host)) { $value = $host; $msg = "is not a valid email domain"; } } } break; case 'date': $timestamp = strtotime($value); if (date('Y-m-d', $timestamp) != $value) { $msg = 'is not a valid date'; } break; case 'timestamp': if (!((string) (int) $value === (string) $value && $value <= PHP_INT_MAX && $value >= ~PHP_INT_MAX)) { $msg = 'is not a valid timestamp'; } break; case 'percent': if (Numbers::between($value, 0, 100)) { $msg = 'is not a valid percentage'; } break; case 'lessthan': case 'lt': if ((int) $value >= (int) $options) { $msg = 'is not less than ' . (int) $options; } break; case 'lessthanequal': case 'lte': if ((int) $value > (int) $options) { $msg = 'is not less than or equal to ' . (int) $options; } break; case 'greaterthan': case 'gt': if ((int) $value <= (int) $options) { $msg = 'is not greater than ' . (int) $options; } break; case 'greaterthanequal': case 'gte': if ((int) $value < (int) $options) { $msg = 'is not greater than or equal to ' . (int) $options; } break; } if ($msg !== null) { throw PVE::create($property, $value, $msg); } return null; }