summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http/api-inc.php24
1 files changed, 12 insertions, 12 deletions
diff --git a/http/api-inc.php b/http/api-inc.php
index e70957e..3163618 100644
--- a/http/api-inc.php
+++ b/http/api-inc.php
@@ -26,6 +26,10 @@ function recursive_ksort(&$array, $flags = SORT_REGULAR) {
return true;
}
+function is_integer_like($value) {
+ return ctype_digit($value) || is_int($value);
+}
+
class ParametersException extends Exception {};
function run($parameters) {
@@ -61,10 +65,6 @@ class ApiPkl {
$this->parameters = $this->parse_parameters($parameters);
}
- protected function is_integer($value) {
- return ctype_digit($value) || is_int($value);
- }
-
function ensure_parameters($params) {
foreach ($params as $param) {
if (!isset($this->parameters[$param])) {
@@ -87,12 +87,12 @@ class ApiPkl {
function check_parameters() {
$this->ensure_parameters(array('type', 'contestants'));
$this->check_values($this->parameters, array(
- 'type' => function($r) { return $this->is_integer($r) && intval($r) > 0; },
- 'contestants' => function($r) { return $this->is_integer($r) && intval($r) > 0; }
+ 'type' => function($r) { return is_integer_like($r) && intval($r) > 0; },
+ 'contestants' => function($r) { return is_integer_like($r) && intval($r) > 0; }
));
if (isset($this->parameters['players'])) {
$this->check_values($this->parameters, array(
- 'players' => function($r) { return $this->is_integer($r) && intval($r) > 0; }
+ 'players' => function($r) { return is_integer_like($r) && intval($r) > 0; }
));
}
if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points'])) {
@@ -103,17 +103,17 @@ class ApiPkl {
if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['tournament_weight'])) {
$this->ensure_parameters(array('tournament_rank', 'over39_boards'));
$this->check_values($this->parameters, array(
- 'tournament_rank' => function($r) { return $this->is_integer($r) && ((intval($r) >= 0 && intval($r) <= 7) || in_array(intval($r), array(ApiPkl::RANK_KMP, ApiPkl::RANK_BNET))); },
- 'over39_boards' => function($r) { return $this->is_integer($r) && intval($r) >= 0 && intval($r) <= 1; }
+ 'tournament_rank' => function($r) { return is_integer_like($r) && ((intval($r) >= 0 && intval($r) <= 7) || in_array(intval($r), array(ApiPkl::RANK_KMP, ApiPkl::RANK_BNET))); },
+ 'over39_boards' => function($r) { return is_integer_like($r) && intval($r) >= 0 && intval($r) <= 1; }
));
} else {
$this->check_values($this->parameters['manual'], array(
- 'tournament_weight' => function($r) { return $this->is_integer($r) && intval($r) > 0; }
+ 'tournament_weight' => function($r) { return is_integer_like($r) && intval($r) > 0; }
));
}
} else {
$this->check_values($this->parameters['manual'], array(
- 'min_points' => function($r) { return $this->is_integer($r) && intval($r) >= 0; }
+ 'min_points' => function($r) { return is_integer_like($r) && intval($r) >= 0; }
));
}
if (isset($this->parameters['manual']) && isset($this->parameters['manual']['players_coefficient'])) {
@@ -280,7 +280,7 @@ class ApiPklV3 extends ApiPklV2 {
}
if (isset($this->parameters['boards'])) {
$this->check_values($this->parameters, array(
- 'boards' => function($r) { return $this->is_integer($r); }
+ 'boards' => function($r) { return is_integer_like($r); }
));
$this->parameters['over39_boards'] = strval(intval($this->parameters['boards'] > 39));
}