Paste->formFormData method changed to Paste->forFormDataAndIp
This commit is contained in:
parent
48172fb9c1
commit
6a2f15d1d6
|
@ -24,9 +24,8 @@ class PasteController extends AbstractController
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$pasteData = $form->getData();
|
$pasteData = $form->getData();
|
||||||
$pasteData->ip = $request->getClientIp();
|
|
||||||
|
|
||||||
$paste = Paste::fromFormData($pasteData);
|
$paste = Paste::fromFormDataAndIp($pasteData, $request->getClientIp());
|
||||||
$pasteRepository->save($paste, true);
|
$pasteRepository->save($paste, true);
|
||||||
|
|
||||||
return $this->redirectToRoute($request->attributes->get('_route'));
|
return $this->redirectToRoute($request->attributes->get('_route'));
|
||||||
|
|
|
@ -18,7 +18,6 @@ class PasteFormData
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank]
|
||||||
public string $author = 'anonymous';
|
public string $author = 'anonymous';
|
||||||
public ?\DateTimeImmutable $expirationDate;
|
public ?\DateTimeImmutable $expirationDate;
|
||||||
public string $ip;
|
|
||||||
|
|
||||||
public function __construct(?Paste $paste=null)
|
public function __construct(?Paste $paste=null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Paste
|
||||||
public readonly ?string $secret,
|
public readonly ?string $secret,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public static function fromFormData(PasteFormData $pasteFormData): Paste
|
public static function fromFormDataAndIp(PasteFormData $pasteFormData, $ip): Paste
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
$pasteFormData->text,
|
$pasteFormData->text,
|
||||||
|
@ -45,7 +45,7 @@ class Paste
|
||||||
$pasteFormData->author,
|
$pasteFormData->author,
|
||||||
new \DateTimeImmutable(),
|
new \DateTimeImmutable(),
|
||||||
$pasteFormData->expirationDate,
|
$pasteFormData->expirationDate,
|
||||||
$pasteFormData->ip,
|
$ip,
|
||||||
$pasteFormData->private ? \hash('sha1', \random_bytes(25)) : null,
|
$pasteFormData->private ? \hash('sha1', \random_bytes(25)) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue