diff --git a/lib/Alternc/Api/Legacyobject.php b/lib/Alternc/Api/Legacyobject.php index a66b6bdf..cdf7fc85 100644 --- a/lib/Alternc/Api/Legacyobject.php +++ b/lib/Alternc/Api/Legacyobject.php @@ -39,6 +39,25 @@ class Alternc_Api_Legacyobject { return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error)); } + /** ensure that offset & count are set properly from $options. + */ + protected function offsetAndCount($options, $max) { + $offset = -1; + $count = -1; + if (isset($options["count"])) + $count = intval($options["count"]); + if (isset($options["offset"])) + $offset = intval($options["offset"]); + if ($offset != -1 || $count != -1) { + if ($offset < 0 || $offset > $max) + $offset = 0; + if ($count < 0 || $count > 1000) + $count = 1000; + } + return array($offset, $count); + } + } -/* Aternc_Api_Legacyobject */ +// Aternc_Api_Legacyobject + diff --git a/lib/Alternc/Api/Object/Account.php b/lib/Alternc/Api/Object/Account.php index e2d7aa20..35984134 100644 --- a/lib/Alternc/Api/Object/Account.php +++ b/lib/Alternc/Api/Object/Account.php @@ -171,17 +171,8 @@ class Alternc_Api_Object_Account extends Alternc_Api_Legacyobject { if (!$result) { return $this->alterncLegacyErrorManager(); } else { - $offset = -1; - $count = -1; - if (isset($options["count"])) - $count = intval($options["count"]); - if (isset($options["offset"])) - $offset = intval($options["offset"]); + list($offset, $count) = $this->offsetAndCount($options, count($result)); if ($offset != -1 || $count != -1) { - if ($offset < 0 || $offset > count($result)) - $offset = 0; - if ($count < 0 || $count > 1000) - $count = 1000; $result = array_slice($result, $offset, $count); } return new Alternc_Api_Response(array("content" => $result)); diff --git a/lib/Alternc/Api/Object/Domain.php b/lib/Alternc/Api/Object/Domain.php index 14809cd5..1ec98367 100644 --- a/lib/Alternc/Api/Object/Domain.php +++ b/lib/Alternc/Api/Object/Domain.php @@ -44,17 +44,8 @@ class Alternc_Api_Object_Domain extends Alternc_Api_Legacyobject { while ($me = $stmt->fetch(PDO::FETCH_OBJ)) { $result[$me->domaine] = $me; } - $offset = -1; - $count = -1; - if (isset($options["count"])) - $count = intval($options["count"]); - if (isset($options["offset"])) - $offset = intval($options["offset"]); + list($offset,$count)=$this->offsetAndCount($options, count($result)); if ($offset != -1 || $count != -1) { - if ($offset < 0 || $offset > count($result)) - $offset = 0; - if ($count < 0 || $count > 1000) - $count = 1000; $result = array_slice($result, $offset, $count); } return new Alternc_Api_Response(array("content" => $result)); diff --git a/lib/Alternc/Api/Object/Ftp.php b/lib/Alternc/Api/Object/Ftp.php index 4a921a54..ef0a6ff4 100644 --- a/lib/Alternc/Api/Object/Ftp.php +++ b/lib/Alternc/Api/Object/Ftp.php @@ -96,17 +96,8 @@ class Alternc_Api_Object_Ftp extends Alternc_Api_Legacyobject { if (!$result) { return $this->alterncLegacyErrorManager(); } else { - $offset = -1; - $count = -1; - if (isset($options["count"])) - $count = intval($options["count"]); - if (isset($options["offset"])) - $offset = intval($options["offset"]); + list($offset, $count) = $this->offsetAndCount($options, count($result)); if ($offset != -1 || $count != -1) { - if ($offset < 0 || $offset > count($result)) - $offset = 0; - if ($count < 0 || $count > 1000) - $count = 1000; $result = array_slice($result, $offset, $count); } return new Alternc_Api_Response(array("content" => $result));