public static function Interval::test in Plug 7
Tests if the given number is in the math interval.
Parameters
int $number A number:
string $interval An interval:
Return value
bool
Throws
\InvalidArgumentException
3 calls to Interval::test()
- IntervalTest::testTest in lib/
Symfony/ translation/ Tests/ IntervalTest.php - @dataProvider getTests
- IntervalTest::testTestException in lib/
Symfony/ translation/ Tests/ IntervalTest.php - @expectedException \InvalidArgumentException
- MessageSelector::choose in lib/
Symfony/ translation/ MessageSelector.php - Given a message with different plural translations separated by a pipe (|), this method returns the correct portion of the message based on the given number, locale and the pluralization rules in the message itself.
File
- lib/
Symfony/ translation/ Interval.php, line 46
Class
- Interval
- Tests if a given number belongs to a given math interval.
Namespace
Symfony\Component\TranslationCode
public static function test($number, $interval) {
$interval = trim($interval);
if (!preg_match('/^' . self::getIntervalRegexp() . '$/x', $interval, $matches)) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid interval.', $interval));
}
if ($matches[1]) {
foreach (explode(',', $matches[2]) as $n) {
if ($number == $n) {
return true;
}
}
}
else {
$leftNumber = self::convertNumber($matches['left']);
$rightNumber = self::convertNumber($matches['right']);
return ('[' === $matches['left_delimiter'] ? $number >= $leftNumber : $number > $leftNumber) && (']' === $matches['right_delimiter'] ? $number <= $rightNumber : $number < $rightNumber);
}
return false;
}