summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/sql/src/LimitOffset.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
commit1ff5c35de5dbd70a782875a91dd2232fd01b002b (patch)
tree77d9ce5e1bf78b3e6ef79f8f6e7861e2ced3c09b /vendor/ipl/sql/src/LimitOffset.php
parentInitial commit. (diff)
downloadicinga-php-library-1ff5c35de5dbd70a782875a91dd2232fd01b002b.tar.xz
icinga-php-library-1ff5c35de5dbd70a782875a91dd2232fd01b002b.zip
Adding upstream version 0.10.1.upstream/0.10.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ipl/sql/src/LimitOffset.php')
-rw-r--r--vendor/ipl/sql/src/LimitOffset.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/ipl/sql/src/LimitOffset.php b/vendor/ipl/sql/src/LimitOffset.php
new file mode 100644
index 0000000..99c30a2
--- /dev/null
+++ b/vendor/ipl/sql/src/LimitOffset.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace ipl\Sql;
+
+/**
+ * Implementation for the {@link LimitOffsetInterface} to allow pagination via {@link limit()} and {@link offset()}
+ */
+trait LimitOffset
+{
+ /**
+ * The maximum number of how many items to return
+ *
+ * If unset or lower than 0, no limit will be applied.
+ *
+ * @var int|null
+ */
+ protected $limit;
+
+ /**
+ * Offset from where to start the result set
+ *
+ * If unset or lower than 0, the result set will start from the beginning.
+ *
+ * @var int|null
+ */
+ protected $offset;
+
+ public function hasLimit()
+ {
+ return $this->limit !== null;
+ }
+
+ public function getLimit()
+ {
+ return $this->limit;
+ }
+
+ public function limit($limit)
+ {
+ if ($limit !== null) {
+ $limit = (int) $limit;
+ if ($limit < 0) {
+ $limit = null;
+ }
+ }
+
+ $this->limit = $limit;
+
+ return $this;
+ }
+
+ public function resetLimit()
+ {
+ $this->limit = null;
+
+ return $this;
+ }
+
+ public function hasOffset()
+ {
+ return $this->offset !== null;
+ }
+
+ public function getOffset()
+ {
+ return $this->offset;
+ }
+
+ public function offset($offset)
+ {
+ if ($offset !== null) {
+ $offset = (int) $offset;
+ if ($offset <= 0) {
+ $offset = null;
+ }
+ }
+
+ $this->offset = $offset;
+
+ return $this;
+ }
+
+ public function resetOffset()
+ {
+ $this->offset = null;
+
+ return $this;
+ }
+}