WIP: feature_paste #1
0
migrations/.gitignore
vendored
0
src/Controller/.gitignore
vendored
|
@ -26,7 +26,7 @@ class PasteController extends AbstractController
|
||||||
$paste->setPublishDate(new \DateTime());
|
$paste->setPublishDate(new \DateTime());
|
||||||
skobkin marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Do you need IP in Do you need IP in `PasteData`?
|
|||||||
if ($paste->isPrivate()) {
|
if ($paste->isPrivate()) {
|
||||||
$paste->setSecret(hash("sha1", random_bytes(25)));
|
$paste->setSecret(hash('sha1', random_bytes(25)));
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Do we need double quotes here? By the way, we can also do that in the constructor. Do we need double quotes here?
By the way, we can also do that in the constructor.
skobkin marked this conversation as resolved
Outdated
skobkin
commented
This still could be done in the entity itself. This still could be done in the entity itself.
|
|||||||
}
|
}
|
||||||
|
|
||||||
$entityManager->persist($paste);
|
$entityManager->persist($paste);
|
||||||
|
@ -43,7 +43,7 @@ class PasteController extends AbstractController
|
||||||
|
|
||||||
#[Route('/{id}/{secret}')]
|
#[Route('/{id}/{secret}')]
|
||||||
public function show_paste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response {
|
public function show_paste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response {
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
You're violating Symfony code style here which as I can guess you used above. You can just set Symfony style in the settings of your IDE for this project and auto-format this file to fix. Or fix it manually if you want. You're violating [Symfony code style](https://symfony.com/doc/current/contributing/code/standards.html#symfony-coding-standards-in-detail) here which as I can guess you used above.
You can just set Symfony style in the settings of your IDE for this project and auto-format this file to fix. Or fix it manually if you want.
|
|||||||
$paste = $pasteRepository->findOneBy(["id" => $id, "secret" => $secret]);
|
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Do you need double quotes here too? Do you need double quotes here too?
|
|||||||
$form = $this->createForm(PasteForm::class, $paste);
|
$form = $this->createForm(PasteForm::class, $paste);
|
||||||
|
|
||||||
return $this->render('paste.html.twig', [
|
return $this->render('paste.html.twig', [
|
||||||
skobkin
commented
I'd suggest you implementing Twig extension wih filter and function to use highlighter in the template. I'd suggest you implementing Twig extension wih filter and function to use highlighter in the template.
|
|||||||
|
|
|
@ -14,18 +14,18 @@ class Paste
|
||||||
#[ORM\Column(nullable: false)]
|
#[ORM\Column(nullable: false)]
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
I don't think you need But I'd suggest to explicitly set it for every other I don't think you need `nullable=false` here since it's a Primary Key.
But I'd suggest to explicitly set it for every other `Column` and also set a `name` for them.
|
|||||||
private int $id;
|
private int $id;
|
||||||
skobkin
commented
Why not also constructor promotion though? Why not also constructor promotion though?
|
|||||||
|
|
||||||
#[ORM\Column(type: "text", nullable: false)]
|
#[ORM\Column(type: 'text', nullable: false)]
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
No need for double quotes here too. No need for double quotes here too.
|
|||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank]
|
||||||
private string $text;
|
private string $text;
|
||||||
|
|
||||||
#[ORM\Column(type: "boolean", nullable: false)]
|
#[ORM\Column(type: 'boolean', nullable: false)]
|
||||||
#[Assert\Type(\boolean::class)]
|
#[Assert\Type(\boolean::class)]
|
||||||
private bool $private;
|
private bool $private;
|
||||||
|
|
||||||
#[ORM\Column(length: 25, nullable: true)]
|
#[ORM\Column(length: 25, nullable: true)]
|
||||||
skobkin
commented
What type? Why 25 exactly? What type? Why 25 exactly?
skobkin
commented
Why 128? Why 128?
|
|||||||
private ?string $language;
|
private ?string $language;
|
||||||
|
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Why not nullable? Why not nullable?
|
|||||||
#[ORM\Column(type: "text", nullable: true)]
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
private ?string $description;
|
private ?string $description;
|
||||||
|
|
||||||
#[ORM\Column(length: 128, nullable: true)]
|
#[ORM\Column(length: 128, nullable: true)]
|
||||||
|
@ -33,7 +33,7 @@ class Paste
|
||||||
|
|
||||||
#[ORM\Column(length: 128, nullable: false)]
|
#[ORM\Column(length: 128, nullable: false)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank]
|
||||||
private string $author = "anonymous";
|
private string $author = 'anonymous';
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Why double quotes? Why double quotes?
|
|||||||
|
|
||||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: false)]
|
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: false)]
|
||||||
skobkin
commented
You can use You can use `self` as return type hint too.
|
|||||||
#[Assert\Type(\DateTime::class)]
|
#[Assert\Type(\DateTime::class)]
|
||||||
|
|
|
@ -15,14 +15,14 @@ class PasteForm extends AbstractType
|
||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void {
|
public function buildForm(FormBuilderInterface $builder, array $options): void {
|
||||||
$builder
|
$builder
|
||||||
->add("language", ChoiceType::class, ["choices" => ["Python" => "python", "PHP" => "php", "Plain text" => NULL]])
|
->add('language', ChoiceType::class, ['choices' => ['Python' => 'python', 'PHP' => 'php', 'Plain text' => NULL]])
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
Double quotes? Also please multi-line format arrays with more than one element for readability. Double quotes?
Also please multi-line format arrays with more than one element for readability.
|
|||||||
->add("description", TextType::class, ["required" => false])
|
->add('description', TextType::class, ['required' => false])
|
||||||
->add("text", TextareaType::class)
|
->add('text', TextareaType::class)
|
||||||
->add("author", TextType::class, ["attr" => ["maxlength" =>128]])
|
->add('author', TextType::class, ['attr' => ['maxlength' =>128]])
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
You can probably extract You can probably extract `128` to the constant and use here and in the validation attribute.
|
|||||||
->add("filename", TextType::class, ["required" => false, "attr" => ["maxlength" =>128]])
|
->add('filename', TextType::class, ['required' => false, 'attr' => ['maxlength' =>128]])
|
||||||
->add("expirationDate", DateTimeType::class, ["required" => false, "date_widget" => "single_text", "input" => "datetime"])
|
->add('expirationDate', DateTimeType::class, ['required' => false, 'date_widget' => 'single_text', 'input' => 'datetime'])
|
||||||
skobkin marked this conversation as resolved
Outdated
skobkin
commented
This should be a combo-box ( This should be a combo-box (`select` in HTML terms) with a list of available periods like "10 minutes", "1 year" and "Never".
|
|||||||
->add("private", CheckboxType::class, ["required" => false])
|
->add('private', CheckboxType::class, ['required' => false])
|
||||||
->add("save", SubmitType::class)
|
->add('save', SubmitType::class)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
You can just set it in the constructor.