*/ protected function getJsonInput(): array { $input = file_get_contents('php://input'); if ($input === false || $input === '') { return []; } $decoded = json_decode($input, true); return is_array($decoded) ? $decoded : []; } /** * Decode JSON string to array with safe defaults. * * @return array */ protected function decodeJson(?string $json): array { if ($json === null || $json === '') { return []; } $decoded = json_decode($json, true); return is_array($decoded) ? $decoded : []; } protected function getInput(string $key, mixed $default = null): mixed { return $_GET[$key] ?? $_POST[$key] ?? $default; } protected function getString(string $key, string $default = ''): string { $value = $this->getInput($key, $default); return is_string($value) ? trim($value) : $default; } protected function getInt(string $key, int $default = 0): int { return (int) ($this->getInput($key, $default)); } protected function getPage(): int { return max(1, $this->getInt('page', 1)); } protected function getLimit(int $max = 50, int $default = 10): int { return min($max, max(1, $this->getInt('limit', $default))); } protected function getOffset(int $limit): int { return ($this->getPage() - 1) * $limit; } protected function getPagination(int $defaultLimit = 50, int $maxLimit = Constants::DEFAULT_LIMIT): \Domain\ValueObject\Pagination { $page = $this->getPage(); $limit = $this->getLimit($maxLimit, $defaultLimit); return \Domain\ValueObject\Pagination::create($page, $limit, $maxLimit); } }