From 6a2f15d1d6ed9eb7f8b31321e691accf6bc49bd5 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sun, 23 Jul 2023 13:51:02 +0300 Subject: [PATCH] Paste->formFormData method changed to Paste->forFormDataAndIp --- src/Controller/PasteController.php | 3 +-- src/DTO/PasteFormData.php | 1 - src/Entity/Paste.php | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Controller/PasteController.php b/src/Controller/PasteController.php index 67fad63..f707eb4 100644 --- a/src/Controller/PasteController.php +++ b/src/Controller/PasteController.php @@ -24,9 +24,8 @@ class PasteController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $pasteData = $form->getData(); - $pasteData->ip = $request->getClientIp(); - $paste = Paste::fromFormData($pasteData); + $paste = Paste::fromFormDataAndIp($pasteData, $request->getClientIp()); $pasteRepository->save($paste, true); return $this->redirectToRoute($request->attributes->get('_route')); diff --git a/src/DTO/PasteFormData.php b/src/DTO/PasteFormData.php index 3e77db3..075b62a 100644 --- a/src/DTO/PasteFormData.php +++ b/src/DTO/PasteFormData.php @@ -18,7 +18,6 @@ class PasteFormData #[Assert\NotBlank] public string $author = 'anonymous'; public ?\DateTimeImmutable $expirationDate; - public string $ip; public function __construct(?Paste $paste=null) { diff --git a/src/Entity/Paste.php b/src/Entity/Paste.php index f797c5f..11b91ce 100644 --- a/src/Entity/Paste.php +++ b/src/Entity/Paste.php @@ -35,7 +35,7 @@ class Paste public readonly ?string $secret, ) {} - public static function fromFormData(PasteFormData $pasteFormData): Paste + public static function fromFormDataAndIp(PasteFormData $pasteFormData, $ip): Paste { return new self( $pasteFormData->text, @@ -45,7 +45,7 @@ class Paste $pasteFormData->author, new \DateTimeImmutable(), $pasteFormData->expirationDate, - $pasteFormData->ip, + $ip, $pasteFormData->private ? \hash('sha1', \random_bytes(25)) : null, ); }