RelationController.php
- Pfad:
src/Controller/RelationController.php - Namespace: Controller
- Zeilen: 202 | Größe: 5,831 Bytes
- Geändert: 2025-12-27 12:30:10 | 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 8
- extends Framework\Controller
- constructor Domain\Repository\RelationRepositoryInterface
- constructor Domain\Repository\EntityRepositoryInterface
- constructor Infrastructure\Formatter\ApiResponseFormatter
- use Domain\Repository\EntityRepositoryInterface
- use Domain\Repository\RelationRepositoryInterface
- use Framework\Controller
- use Infrastructure\Formatter\ApiResponseFormatter
Klassen 1
-
RelationControllerclass Zeile 14
Funktionen 7
-
__construct()public Zeile 20 -
index()public Zeile 34 -
create()public Zeile 54 -
store()public Zeile 66 -
edit()public Zeile 114 -
update()public Zeile 132 -
destroy()public Zeile 178
Versionen 16
-
v16
2025-12-27 12:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v15
2025-12-27 12:29 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v14
2025-12-25 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v13
2025-12-25 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-25 02:29 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-25 02:29 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-25 02:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-25 02:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-25 02:28 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-23 07:52 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-23 04:42 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-22 15:50 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 15:50 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 15:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 08:05 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-22 08:05 | 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 Semantic Explorer Relationen (CRUD)
use Domain\Repository\EntityRepositoryInterface;
use Domain\Repository\RelationRepositoryInterface;
use Framework\Controller;
use Infrastructure\Formatter\ApiResponseFormatter;
class RelationController extends Controller
{
private RelationRepositoryInterface $relationRepository;
private EntityRepositoryInterface $entityRepository;
private ApiResponseFormatter $apiFormatter;
public function __construct(
RelationRepositoryInterface $relationRepository,
EntityRepositoryInterface $entityRepository,
ApiResponseFormatter $apiFormatter
) {
$this->relationRepository = $relationRepository;
$this->entityRepository = $entityRepository;
$this->apiFormatter = $apiFormatter;
}
/**
* GET /semantic-explorer/relationen
* Beziehungen zwischen Entitaeten
*/
public function index(): void
{
$type = $this->getString('type');
$relations = $this->relationRepository->findFiltered($type);
$relationTypes = $this->relationRepository->getTypes();
$stats = $this->relationRepository->getStats();
$this->view('semantic-explorer.relationen', [
'title' => 'Relationen',
'relations' => $relations,
'relationTypes' => $relationTypes,
'stats' => $stats,
'currentType' => $type,
]);
}
/**
* GET /semantic-explorer/relationen/new
*/
public function create(): void
{
$this->view('semantic-explorer.relationen.new', [
'title' => 'Neue Relation',
'entities' => $this->entityRepository->findAllSimple(),
'relationTypes' => $this->relationRepository->getTypesList(),
]);
}
/**
* POST /semantic-explorer/relationen
*/
public function store(): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$sourceId = (int) ($input['source_entity_id'] ?? 0);
$targetId = (int) ($input['target_entity_id'] ?? 0);
$type = trim($input['relation_type'] ?? '');
$strength = (float) ($input['strength'] ?? 1.0);
if ($sourceId === 0 || $targetId === 0 || $type === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Alle Felder sind erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Alle Felder sind erforderlich'), 400);
return;
}
try {
$id = $this->relationRepository->create($sourceId, $targetId, $type, $strength);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/relationen');
return;
}
$this->json($this->apiFormatter->created($id, 'Relation erstellt'));
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* GET /semantic-explorer/relationen/{id}/edit
*/
public function edit(int $id): void
{
$relation = $this->relationRepository->find($id);
if ($relation === null) {
$this->notFound('Relation nicht gefunden');
}
$this->view('semantic-explorer.relationen.edit', [
'title' => 'Relation bearbeiten',
'relation' => $relation,
'relationTypes' => $this->relationRepository->getTypesList(),
]);
}
/**
* POST /semantic-explorer/relationen/{id}
*/
public function update(int $id): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$type = trim($input['relation_type'] ?? '');
$strength = (float) ($input['strength'] ?? 1.0);
if ($type === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Beziehungstyp ist erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);
return;
}
try {
$this->relationRepository->update($id, $type, $strength);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/relationen');
return;
}
$this->json($this->apiFormatter->ok('Relation aktualisiert'));
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* POST /semantic-explorer/relationen/{id}/delete
*/
public function destroy(int $id): void
{
$this->requireCsrf();
try {
$this->relationRepository->delete($id);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/relationen');
return;
}
$this->json($this->apiFormatter->ok('Relation gelöscht'));
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
}