WIP: feature_paste #1
|
@ -6,7 +6,6 @@ namespace App\Controller;
|
||||||
use App\Form\Type\PasteForm;
|
use App\Form\Type\PasteForm;
|
||||||
use App\Entity\Paste;
|
use App\Entity\Paste;
|
||||||
use App\Repository\PasteRepository;
|
use App\Repository\PasteRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -16,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
class PasteController extends AbstractController
|
class PasteController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/')]
|
#[Route('/')]
|
||||||
|
|||||||
public function new(Request $request, EntityManagerInterface $entityManager): 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);
|
||||||
|
|
||||||
|
@ -30,8 +29,7 @@ class PasteController extends AbstractController
|
||||||
$paste->setSecret(hash('sha1', random_bytes(25)));
|
$paste->setSecret(hash('sha1', random_bytes(25)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$entityManager->persist($paste);
|
$pasteRepository->save($paste);
|
||||||
$entityManager->flush();
|
|
||||||
|
|
||||||
return $this->redirectToRoute($request->attributes->get('_route'));
|
return $this->redirectToRoute($request->attributes->get('_route'));
|
||||||
|
|
||||||
|
|
|
@ -12,4 +12,10 @@ 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 {
|
||||||
|
$entityManager = $this->getEntityManager();
|
||||||
|
$entityManager->persist($paste);
|
||||||
|
$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.