InputTrait.php
- Pfad:
src/Framework/Http/InputTrait.php - Namespace: Framework\Http
- Zeilen: 84 | Größe: 2,019 Bytes
- Geändert: 2025-12-29 00:18:55 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 1
- use Domain\Constants
Klassen 1
-
InputTraittrait Zeile 11
Funktionen 9
-
getJsonInput()protected Zeile 16 -
decodeJson()protected Zeile 33 -
getInput()protected Zeile 44 -
getString()protected Zeile 49 -
getInt()protected Zeile 56 -
getPage()protected Zeile 61 -
getLimit()protected Zeile 66 -
getOffset()protected Zeile 71 -
getPagination()protected Zeile 76
Verwendet von 2
- Controller.php use
- Controller.php trait
Versionen 1
-
v1
2025-12-29 00:18 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Framework\Http;
// @responsibility: HTTP-Input-Helpers für Controller
use Domain\Constants;
trait InputTrait
{
/**
* @return array<string, mixed>
*/
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<mixed>
*/
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);
}
}