diff --git a/config/routes.yaml b/config/routes.yaml index 29a5f58..2d44904 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -6,6 +6,14 @@ controllersBase: defaults: schemes: [ 'https' ] +controllersEventLog: + resource: + path: ../src/EventLog/Framework/Controller/ + namespace: App\EventLog\Framework\Controller + type: attribute + defaults: + schemes: [ 'https' ] + controllersLibrary: resource: path: ../src/Library/Framework/Controller/ diff --git a/migrations/Version20251101194723.php b/migrations/Version20251101194723.php new file mode 100644 index 0000000..f6de1e7 --- /dev/null +++ b/migrations/Version20251101194723.php @@ -0,0 +1,35 @@ +addSql(<<<'SQL' + ALTER TABLE user_preference CHANGE preference_value preference_value VARCHAR(255) DEFAULT NULL + SQL); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql(<<<'SQL' + ALTER TABLE user_preference CHANGE preference_value preference_value VARCHAR(1024) DEFAULT NULL + SQL); + } +} diff --git a/src/EventLog/Action/Command/AddEventLogCommand.php b/src/EventLog/Action/Command/AddEventLogCommand.php new file mode 100644 index 0000000..55baea1 --- /dev/null +++ b/src/EventLog/Action/Command/AddEventLogCommand.php @@ -0,0 +1,15 @@ + */ +class AddEventLogCommand implements CommandInterface +{ + public function __construct( + public string $type, + public string $message, + public array $context, + ) {} +} diff --git a/src/EventLog/Action/Handler/AddEventLogHandler.php b/src/EventLog/Action/Handler/AddEventLogHandler.php new file mode 100644 index 0000000..f90cf0a --- /dev/null +++ b/src/EventLog/Action/Handler/AddEventLogHandler.php @@ -0,0 +1,28 @@ + */ +class AddEventLogHandler implements HandlerInterface +{ + public function __construct( + private EventLogRepository $repository, + ) {} + + public function handle(CommandInterface $command): ResultInterface + { + $eventLog = $this->repository->insert( + type: $command->type, + message: $command->message, + context: $command->context + ); + return new AddEventLogResult($eventLog); + } +} diff --git a/src/EventLog/Action/Input/AddEventLogInput.php b/src/EventLog/Action/Input/AddEventLogInput.php new file mode 100644 index 0000000..19d3b6c --- /dev/null +++ b/src/EventLog/Action/Input/AddEventLogInput.php @@ -0,0 +1,36 @@ + */ +class AddEventLogInput implements InputInterface +{ + public function __construct( + #[SourceQuery('type')] + #[SourceRequest('type')] + public string $type, + + #[SourceQuery('message')] + #[SourceRequest('message')] + public string $message, + + #[SourceQuery('context')] + #[SourceRequest('context')] + public array $context = [] + ){} + + public function toCommand(): CommandInterface + { + return new AddEventLogCommand( + $this->type, + $this->message, + $this->context + ); + } +} diff --git a/src/EventLog/Action/Result/AddEventLogResult.php b/src/EventLog/Action/Result/AddEventLogResult.php new file mode 100644 index 0000000..9e858e1 --- /dev/null +++ b/src/EventLog/Action/Result/AddEventLogResult.php @@ -0,0 +1,14 @@ + */ +class AddEventLogResult implements ResultInterface +{ + public function __construct( + public EventLog $eventLog, + ) {} +} diff --git a/src/EventLog/Framework/Controller/EventLogController.php b/src/EventLog/Framework/Controller/EventLogController.php new file mode 100644 index 0000000..f3f5b4c --- /dev/null +++ b/src/EventLog/Framework/Controller/EventLogController.php @@ -0,0 +1,28 @@ +broadcaster->alert( + 'Added to queue', + 'This is a testy test!' + ); + + return $this->json([ + 'Success' => 'Published' + ]); + } +} diff --git a/src/EventLog/Framework/Entity/EventLog.php b/src/EventLog/Framework/Entity/EventLog.php new file mode 100644 index 0000000..210f35c --- /dev/null +++ b/src/EventLog/Framework/Entity/EventLog.php @@ -0,0 +1,63 @@ +id; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(?string $type): self + { + $this->type = $type; + return $this; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(?string $message): self + { + $this->message = $message; + return $this; + } + + public function getContext(): ?array + { + return $this->context; + } + + public function setContext(?array $context): self + { + $this->context = $context; + return $this; + } +} diff --git a/src/EventLog/Framework/Repository/EventLogRepository.php b/src/EventLog/Framework/Repository/EventLogRepository.php new file mode 100644 index 0000000..fb0ecf5 --- /dev/null +++ b/src/EventLog/Framework/Repository/EventLogRepository.php @@ -0,0 +1,32 @@ + + */ +class EventLogRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, EventLog::class); + } + + public function insert( + string $type, + string $message, + array $context = [] + ): EventLog { + $eventLog = new EventLog() + ->setType($type) + ->setMessage($message) + ->setContext($context); + $this->getEntityManager()->persist($eventLog); + $this->getEntityManager()->flush(); + return $eventLog; + } +}