Backup #2093
| ID | 2093 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Framework/Http/InputTrait.php |
| Version | 1 |
| Typ |
modified |
| Größe | 2.0 KB |
| Hash | 190b211ee1794206016e562a868a22f4485e49773de9dcc78f9efaca8a814bd4 |
| Datum | 2025-12-29 00:18:55 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Framework\Controller;
// @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);
}
}
Vollständig herunterladen
Aktionen
← Zurück zur Übersicht