WIP: feature_paste #1
|
@ -26,18 +26,18 @@ class PasteController extends AbstractController
|
|||
$pasteData = $form->getData();
|
||||
|
||||
$secret = null;
|
||||
if ($pasteData->isPrivate()) {
|
||||
if ($pasteData->private) {
|
||||
$secret = hash('sha1', random_bytes(25));
|
||||
}
|
||||
|
||||
$paste = new Paste(
|
||||
$pasteData->getText(),
|
||||
$pasteData->getLanguage(),
|
||||
$pasteData->getDescription(),
|
||||
$pasteData->getFilename(),
|
||||
$pasteData->getAuthor(),
|
||||
$pasteData->text,
|
||||
$pasteData->language,
|
||||
$pasteData->description,
|
||||
$pasteData->filename,
|
||||
$pasteData->author,
|
||||
new \DateTimeImmutable(),
|
||||
$pasteData->getExpirationDate(),
|
||||
$pasteData->expirationDate,
|
||||
|
||||
$request->getClientIp(),
|
||||
$secret
|
||||
);
|
||||
|
@ -52,10 +52,11 @@ class PasteController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/{id}/{secret}')]
|
||||
public function showPaste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response
|
||||
public function showPaste(PasteRepository $pasteRepository, string $id, ?string $secret=NULL): Response
|
||||
{
|
||||
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
|
||||
$form = $this->createForm(PasteForm::class, $paste);
|
||||
$pasteData = new PasteFormData($paste);
|
||||
$form = $this->createForm(PasteForm::class, $pasteData);
|
||||
|
||||
return $this->render('paste.html.twig', [
|
||||
'form' => $form,
|
||||
|
|
|
@ -3,120 +3,36 @@ declare(strict_types = 1);
|
|||
|
||||
namespace App\DTO;
|
||||
|
||||
use App\Entity\Paste;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
|
||||
class PasteFormData
|
||||
{
|
||||
private int $id;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
private string $text;
|
||||
|
||||
public string $text;
|
||||
#[Assert\Type(\boolean::class)]
|
||||
private bool $private;
|
||||
|
||||
private ?string $language = null;
|
||||
|
||||
private ?string $description = null;
|
||||
|
||||
private ?string $filename = null;
|
||||
|
||||
public bool $private;
|
||||
public ?string $language = null;
|
||||
public ?string $description = null;
|
||||
public ?string $filename = null;
|
||||
#[Assert\NotBlank]
|
||||
private string $author = 'anonymous';
|
||||
|
||||
public string $author = 'anonymous';
|
||||
skobkin marked this conversation as resolved
skobkin
commented
Why Why `string` and `Assert\NotBlank`?
|
||||
#[Assert\Type(\DateTimeImmutable::class)]
|
||||
private ?\DateTimeImmutable $expirationDate;
|
||||
public ?\DateTimeImmutable $expirationDate;
|
||||
skobkin marked this conversation as resolved
skobkin
commented
Is this validation being processed BEFORE storing the data in the DTO? Is this validation being processed BEFORE storing the data in the DTO?
If not, it's pointless as with `bool` field earlier.
|
||||
|
||||
private ?string $secret;
|
||||
|
||||
public function getId(): int
|
||||
public function __construct(?Paste $paste=null)
|
||||
skobkin marked this conversation as resolved
skobkin
commented
Or you can make constructor Or you can make constructor `private`, use property promotion and add `fromPaste()` method to create it from the entity.
|
||||
{
|
||||
return $this->id;
|
||||
if ($paste === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getText(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function setText(string $text): void
|
||||
{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function getLanguage(): ?string
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function setLanguage(?string $language): void
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getFilename(): ?string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function setFilename(?string $filename): void
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
public function getAuthor(): string
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function setAuthor(string $author): void
|
||||
{
|
||||
$this->author = $author;
|
||||
}
|
||||
|
||||
public function getExpirationDate(): ?\DateTime
|
||||
{
|
||||
return $this->expirationDate;
|
||||
}
|
||||
|
||||
public function setExpirationDate(?\DateTime $date): void
|
||||
{
|
||||
$this->expirationDate = $date;
|
||||
}
|
||||
|
||||
public function getSecret(): ?string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
public function setSecret(?string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
public function isPrivate(): bool
|
||||
{
|
||||
return $this->private;
|
||||
}
|
||||
|
||||
public function setPrivate(bool $private): void
|
||||
{
|
||||
$this->private = $private;
|
||||
$this->text = $paste->text;
|
||||
$this->private = $paste->secret !== null;
|
||||
$this->language = $paste->language;
|
||||
$this->description = $paste->description;
|
||||
$this->filename = $paste->filename;
|
||||
$this->author = $paste->author;
|
||||
$this->expirationDate = $paste->expirationDate;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue
show_paste
at least.