EntityController.php
- Pfad:
src/Controller/EntityController.php - Namespace: Controller
- Zeilen: 235 | Größe: 6,827 Bytes
- Geändert: 2025-12-28 03:00:18 | 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 Domain\Repository\EntityRepositoryInterface
- constructor Infrastructure\Formatter\ApiResponseFormatter
- use Domain\Repository\EntityRepositoryInterface
- use Framework\Controller
- use Infrastructure\Formatter\ApiResponseFormatter
Klassen 1
-
EntityControllerclass Zeile 13
Funktionen 8
-
__construct()public Zeile 18 -
index()public Zeile 30 -
show()public Zeile 51 -
create()public Zeile 81 -
store()public Zeile 92 -
edit()public Zeile 139 -
update()public Zeile 157 -
delete()public Zeile 204
Versionen 18
-
v18
2025-12-28 03:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v17
2025-12-27 12:27 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v16
2025-12-27 12:27 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v15
2025-12-25 09:19 | 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 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-25 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-25 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-25 09:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-25 09:17 | 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:48 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 15:48 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 15:48 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 08:04 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-22 08:04 | 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 Entitäten (CRUD)
use Domain\Repository\EntityRepositoryInterface;
use Framework\Controller;
use Infrastructure\Formatter\ApiResponseFormatter;
class EntityController extends Controller
{
private EntityRepositoryInterface $repository;
private ApiResponseFormatter $apiFormatter;
public function __construct(
EntityRepositoryInterface $repository,
ApiResponseFormatter $apiFormatter
) {
$this->repository = $repository;
$this->apiFormatter = $apiFormatter;
}
/**
* GET /semantic-explorer/entitaeten
* Liste aller Entitaeten
*/
public function index(): void
{
$type = $this->getString('type');
$search = $this->getString('search');
$entities = $this->repository->findFiltered($type, $search);
$stats = $this->repository->getStats();
$this->view('semantic-explorer.entitaeten.index', [
'title' => 'Entitaeten',
'entities' => $entities,
'stats' => $stats,
'currentType' => $type,
'currentSearch' => $search,
]);
}
/**
* GET /semantic-explorer/entitaeten/{id}
* Entitaet-Details
*/
public function show(int $id): void
{
$entity = $this->repository->find($id);
if ($entity === null) {
$this->notFound('Entitaet nicht gefunden');
}
$synonyms = $this->repository->findSynonyms($id);
$outgoingRelations = $this->repository->getOutgoingRelations($id);
$incomingRelations = $this->repository->getIncomingRelations($id);
$chunks = $this->repository->findChunks($id);
$classifications = $this->repository->findClassifications($id);
$knowledgeSemantics = $this->repository->getKnowledgeSemantics($id);
$this->view('semantic-explorer.entitaeten.show', [
'title' => $entity['name'],
'entity' => $entity,
'synonyms' => $synonyms,
'outgoingRelations' => $outgoingRelations,
'incomingRelations' => $incomingRelations,
'chunks' => $chunks,
'classifications' => $classifications,
'knowledgeSemantics' => $knowledgeSemantics,
]);
}
/**
* GET /semantic-explorer/entitaeten/new
*/
public function create(): void
{
$this->view('semantic-explorer.entitaeten.new', [
'title' => 'Neue Entitaet',
'types' => $this->repository->getTypes(),
]);
}
/**
* POST /semantic-explorer/entitaeten
*/
public function store(): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$name = trim($input['name'] ?? '');
$type = trim($input['type'] ?? '');
$description = trim($input['description'] ?? '') ?: null;
if ($name === '' || $type === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Name und Typ sind erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);
return;
}
try {
$id = $this->repository->create($name, $type, $description);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/entitaeten/' . $id);
return;
}
$this->json($this->apiFormatter->created($id, 'Entität 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/entitaeten/{id}/edit
*/
public function edit(int $id): void
{
$entity = $this->repository->find($id);
if ($entity === null) {
$this->notFound('Entitaet nicht gefunden');
}
$this->view('semantic-explorer.entitaeten.edit', [
'title' => 'Entitaet bearbeiten',
'entity' => $entity,
'types' => $this->repository->getTypes(),
]);
}
/**
* POST /semantic-explorer/entitaeten/{id}
*/
public function update(int $id): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$name = trim($input['name'] ?? '');
$type = trim($input['type'] ?? '');
$description = trim($input['description'] ?? '') ?: null;
if ($name === '' || $type === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Name und Typ sind erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);
return;
}
try {
$this->repository->update($id, $name, $type, $description);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/entitaeten/' . $id);
return;
}
$this->json($this->apiFormatter->ok('Entität 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/entitaeten/{id}/delete
*/
public function delete(int $id): void
{
$this->requireCsrf();
try {
$success = $this->repository->delete($id);
if ($success) {
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/entitaeten');
return;
}
$this->json($this->apiFormatter->ok('Entität gelöscht'));
} else {
if ($this->isHtmxRequest()) {
$this->htmxError('Entität hat noch Relationen');
return;
}
$this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);
}
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
}