WIP: feature_paste #1
|
@ -15,7 +15,8 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
class PasteController extends AbstractController
|
class PasteController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/')]
|
#[Route('/')]
|
||||||
|
|||||||
public function new(Request $request, PasteRepository $pasteRepository): Response {
|
public function new(Request $request, PasteRepository $pasteRepository): Response
|
||||||
|
{
|
||||||
$paste = new Paste();
|
$paste = new Paste();
|
||||||
$form = $this->createForm(PasteForm::class, $paste);
|
$form = $this->createForm(PasteForm::class, $paste);
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@ class PasteController extends AbstractController
|
||||||
$pasteRepository->save($paste);
|
$pasteRepository->save($paste);
|
||||||
|
|
||||||
return $this->redirectToRoute($request->attributes->get('_route'));
|
return $this->redirectToRoute($request->attributes->get('_route'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('paste.html.twig', [
|
return $this->render('paste.html.twig', [
|
||||||
|
@ -41,13 +41,13 @@ 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 showPaste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response
|
||||||
|
{
|
||||||
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
|
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
|
||||||
$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.
|
|||||||
'form' => $form,
|
'form' => $form,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,91 +51,113 @@ class Paste
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
private ?string $secret;
|
private ?string $secret;
|
||||||
|
|
||||||
public function getId(): int {
|
public function getId(): int
|
||||||
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setId(int $id): void {
|
public function setId(int $id): void
|
||||||
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getText(): string {
|
public function getText(): string
|
||||||
|
{
|
||||||
return $this->text;
|
return $this->text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setText(string $text): void {
|
public function setText(string $text): void
|
||||||
|
{
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLanguage(): ?string {
|
public function getLanguage(): ?string
|
||||||
|
{
|
||||||
return $this->language;
|
return $this->language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLanguage(?string $language): void {
|
public function setLanguage(?string $language): void
|
||||||
|
{
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription(): ?string {
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDescription(?string $description): void {
|
public function setDescription(?string $description): void
|
||||||
|
{
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilename(): ?string {
|
public function getFilename(): ?string
|
||||||
|
{
|
||||||
return $this->filename;
|
return $this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFilename(?string $filename): void {
|
public function setFilename(?string $filename): void
|
||||||
|
{
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAuthor(): string {
|
public function getAuthor(): string
|
||||||
|
{
|
||||||
return $this->author;
|
return $this->author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAuthor(string $author): void {
|
public function setAuthor(string $author): void
|
||||||
|
{
|
||||||
$this->author = $author;
|
$this->author = $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPublishDate(): \DateTime {
|
public function getPublishDate(): \DateTime
|
||||||
|
{
|
||||||
return $this->publishDate;
|
return $this->publishDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPublishDate(\DateTime $date): void {
|
public function setPublishDate(\DateTime $date): void
|
||||||
|
{
|
||||||
$this->publishDate = $date;
|
$this->publishDate = $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExpirationDate(): ?\DateTime {
|
public function getExpirationDate(): ?\DateTime
|
||||||
|
{
|
||||||
return $this->expirationDate;
|
return $this->expirationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setExpirationDate(?\DateTime $date): void {
|
public function setExpirationDate(?\DateTime $date): void
|
||||||
|
{
|
||||||
$this->expirationDate = $date;
|
$this->expirationDate = $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIp(): string {
|
public function getIp(): string
|
||||||
|
{
|
||||||
return $this->ip;
|
return $this->ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIP(string $ip): void {
|
public function setIP(string $ip): void
|
||||||
|
{
|
||||||
$this->ip = $ip;
|
$this->ip = $ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSecret(): ?string {
|
public function getSecret(): ?string
|
||||||
|
{
|
||||||
return $this->secret;
|
return $this->secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecret(?string $secret): void {
|
public function setSecret(?string $secret): void
|
||||||
|
{
|
||||||
$this->secret = $secret;
|
$this->secret = $secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPrivate(): bool {
|
public function isPrivate(): bool
|
||||||
|
{
|
||||||
return $this->private;
|
return $this->private;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPrivate(bool $private): void {
|
public function setPrivate(bool $private): void
|
||||||
|
{
|
||||||
$this->private = $private;
|
$this->private = $private;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,14 +15,27 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
|
||||||
class PasteForm extends AbstractType
|
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,
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
->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]])
|
||||||
->add('filename', TextType::class, ['required' => false, 'attr' => ['maxlength' =>128]])
|
->add('filename', TextType::class, ['required' => false, 'attr' => ['maxlength' =>128]])
|
||||||
skobkin
commented
Why 128? Why 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',
|
||||||
|
]
|
||||||
|
)
|
||||||
->add('private', CheckboxType::class, ['required' => false])
|
->add('private', CheckboxType::class, ['required' => false])
|
||||||
->add('save', SubmitType::class)
|
->add('save', SubmitType::class)
|
||||||
;
|
;
|
||||||
|
|
|
@ -9,11 +9,13 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
class PasteRepository extends ServiceEntityRepository
|
class PasteRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
public function __construct(ManagerRegistry $registry) {
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
parent::__construct($registry, Paste::class);
|
parent::__construct($registry, Paste::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(Paste $paste): void {
|
public function save(Paste $paste): void
|
||||||
|
{
|
||||||
$entityManager = $this->getEntityManager();
|
$entityManager = $this->getEntityManager();
|
||||||
$entityManager->persist($paste);
|
$entityManager->persist($paste);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
|
Loading…
Reference in a new issue
I'd suggest explicitly defining which request methods we're processing here.
P.S. We'll move this to YAML in the end.