{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Domain\/ValueObject\/Pagination.php"
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Domain\/ValueObject\/Pagination.php",
"content": "<?php\n\nnamespace Domain\\ValueObject;\n\n\/**\n * Pagination Value Object for consistent pagination handling.\n *\n * Immutable object that encapsulates pagination logic.\n * Use fromRequest() for creating from HTTP request parameters.\n *\/\nfinal class Pagination\n{\n public function __construct(\n public readonly int $page,\n public readonly int $limit,\n public readonly int $offset,\n public readonly int $totalCount = 0\n ) {\n }\n\n \/**\n * Create pagination from request parameters.\n *\n * @param int $defaultLimit Default items per page\n * @param int $maxLimit Maximum allowed limit\n *\/\n public static function fromRequest(int $defaultLimit = 50, int $maxLimit = 100): self\n {\n $page = max(1, (int) ($_GET['page'] ?? 1));\n $limit = min($maxLimit, max(1, (int) ($_GET['limit'] ?? $defaultLimit)));\n\n return new self($page, $limit, ($page - 1) * $limit);\n }\n\n \/**\n * Create new instance with total count set.\n *\/\n public function withTotal(int $count): self\n {\n return new self($this->page, $this->limit, $this->offset, $count);\n }\n\n \/**\n * Calculate total number of pages.\n *\/\n public function totalPages(): int\n {\n if ($this->totalCount === 0) {\n return 0;\n }\n\n return (int) ceil($this->totalCount \/ $this->limit);\n }\n\n \/**\n * Check if there is a next page.\n *\/\n public function hasNextPage(): bool\n {\n return $this->page < $this->totalPages();\n }\n\n \/**\n * Check if there is a previous page.\n *\/\n public function hasPrevPage(): bool\n {\n return $this->page > 1;\n }\n\n \/**\n * Get next page number (or current if at last page).\n *\/\n public function nextPage(): int\n {\n return $this->hasNextPage() ? $this->page + 1 : $this->page;\n }\n\n \/**\n * Get previous page number (or 1 if at first page).\n *\/\n public function prevPage(): int\n {\n return $this->hasPrevPage() ? $this->page - 1 : 1;\n }\n\n \/**\n * Get range of visible page numbers for pagination UI.\n *\n * @param int $range Number of pages to show around current page\n * @return array<int>\n *\/\n public function getPageRange(int $range = 2): array\n {\n $totalPages = $this->totalPages();\n\n if ($totalPages === 0) {\n return [];\n }\n\n $start = max(1, $this->page - $range);\n $end = min($totalPages, $this->page + $range);\n\n return range($start, $end);\n }\n\n \/**\n * Convert to array for template usage.\n *\n * @return array{page: int, limit: int, offset: int, totalCount: int, totalPages: int, hasNext: bool, hasPrev: bool}\n *\/\n public function toArray(): array\n {\n return [\n 'page' => $this->page,\n 'limit' => $this->limit,\n 'offset' => $this->offset,\n 'totalCount' => $this->totalCount,\n 'totalPages' => $this->totalPages(),\n 'hasNext' => $this->hasNextPage(),\n 'hasPrev' => $this->hasPrevPage(),\n ];\n }\n}\n",
"numLines": 125,
"startLine": 1,
"totalLines": 125
}
}
}