PromptsController.php
- Pfad:
src/Controller/PromptsController.php - Namespace: Controller
- Zeilen: 227 | Größe: 6,079 Bytes
- Geändert: 2025-12-27 12:46:19 | 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 6
- extends Framework\Controller
- constructor UseCases\Prompts\ManagePromptsUseCase
- use Framework\Controller
- use UseCases\Command\CreatePromptCommand
- use UseCases\Command\UpdatePromptCommand
- use UseCases\Prompts\ManagePromptsUseCase
Klassen 1
-
PromptsControllerclass Zeile 14
Funktionen 9
-
__construct()public Zeile 26 -
index()public Zeile 31 -
promptsNew()public Zeile 41 -
store()public Zeile 51 -
show()public Zeile 96 -
edit()public Zeile 111 -
update()public Zeile 126 -
delete()public Zeile 172 -
duplicate()public Zeile 199
Versionen 17
-
v17
2025-12-27 12:46 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v16
2025-12-27 12:45 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v15
2025-12-27 11:29 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v14
2025-12-23 08:50 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v13
2025-12-23 07:52 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-22 15:42 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-22 15:42 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-22 15:42 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-22 15:26 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-22 15:26 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-22 15:26 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-22 10:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-22 10:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 10:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 10:25 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 10:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-22 10:16 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Controller;
// @responsibility: HTTP-Endpunkte für Prompt-Verwaltung (CRUD, Duplizieren)
use Framework\Controller;
use UseCases\Command\CreatePromptCommand;
use UseCases\Command\UpdatePromptCommand;
use UseCases\Prompts\ManagePromptsUseCase;
class PromptsController extends Controller
{
private ManagePromptsUseCase $promptsUseCase;
private const PROMPT_TYPES = [
'critic' => 'Critic-Prompt',
'generate' => 'Generierungs-Prompt',
'revise' => 'Revisions-Prompt',
'system' => 'System-Prompt',
'other' => 'Sonstiges',
];
public function __construct(ManagePromptsUseCase $promptsUseCase)
{
$this->promptsUseCase = $promptsUseCase;
}
public function index(): void
{
$this->view('prompts.index', [
'title' => 'Prompts verwalten',
'prompts' => array_map(fn ($dto) => $dto->toArray(), $this->promptsUseCase->getAll()),
'stats' => $this->promptsUseCase->getStatistics(),
'promptTypes' => self::PROMPT_TYPES,
]);
}
public function promptsNew(): void
{
$this->view('prompts.form', [
'title' => 'Neuer Prompt',
'prompt' => null,
'promptTypes' => self::PROMPT_TYPES,
'isEdit' => false,
]);
}
public function store(): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
$command = CreatePromptCommand::fromRequest($_POST);
$errors = $command->validate();
if ($errors !== []) {
if ($isHtmx) {
$this->htmxError(implode(' ', $errors));
return;
}
$_SESSION['error'] = implode(' ', $errors);
$this->redirect('/prompts/new');
}
$result = $this->promptsUseCase->create(
name: $command->name,
version: $command->version,
content: $command->content,
isActive: $command->isActive
);
if (!$result->success) {
if ($isHtmx) {
$this->htmxError($result->message);
return;
}
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/new');
}
if ($isHtmx) {
$this->htmxRedirect('/prompts/' . $result->id);
return;
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $result->id);
}
public function show(string $id): void
{
$prompt = $this->promptsUseCase->getById((int) $id);
if ($prompt === null) {
$this->notFound('Prompt nicht gefunden');
}
$this->view('prompts.show', [
'title' => $prompt->name,
'prompt' => $prompt->toArray(),
'linkedCritics' => $this->promptsUseCase->getLinkedCritics((int) $id),
'promptTypes' => self::PROMPT_TYPES,
]);
}
public function edit(string $id): void
{
$prompt = $this->promptsUseCase->getById((int) $id);
if ($prompt === null) {
$this->notFound('Prompt nicht gefunden');
}
$this->view('prompts.form', [
'title' => 'Bearbeiten: ' . $prompt->name,
'prompt' => $prompt->toArray(),
'promptTypes' => self::PROMPT_TYPES,
'isEdit' => true,
]);
}
public function update(string $id): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
$command = UpdatePromptCommand::fromRequest((int) $id, $_POST);
$errors = $command->validate();
if ($errors !== []) {
if ($isHtmx) {
$this->htmxError(implode(' ', $errors));
return;
}
$_SESSION['error'] = implode(' ', $errors);
$this->redirect('/prompts/' . $id . '/edit');
}
$result = $this->promptsUseCase->update(
id: $command->id,
name: $command->name,
version: $command->version,
content: $command->content,
isActive: $command->isActive
);
if (!$result->success) {
if ($isHtmx) {
$this->htmxError($result->message);
return;
}
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/' . $id . '/edit');
}
if ($isHtmx) {
$this->htmxRedirect('/prompts/' . $id);
return;
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $id);
}
public function delete(string $id): void
{
$this->requireCsrf();
$isHtmx = $this->isHtmxRequest();
$result = $this->promptsUseCase->delete((int) $id);
if (!$result->success) {
if ($isHtmx) {
$this->htmxError($result->message);
return;
}
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/' . $id);
}
if ($isHtmx) {
$this->htmxRedirect('/prompts');
return;
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts');
}
public function duplicate(string $id): void
{
$this->requireCsrf();
$result = $this->promptsUseCase->duplicate((int) $id);
// HTMX request handling
if ($this->isHtmxRequest()) {
if (!$result->success) {
$this->htmxError($result->message);
return;
}
$this->htmxRedirect('/prompts/' . $result->id . '/edit');
return;
}
// Traditional form fallback
if (!$result->success) {
$_SESSION['error'] = $result->message;
$this->redirect('/prompts/' . $id);
}
$_SESSION['success'] = $result->message;
$this->redirect('/prompts/' . $result->id . '/edit');
}
}