diff --git a/src/Controller/PasteController.php b/src/Controller/PasteController.php index 9cb01bf..812c4e3 100644 --- a/src/Controller/PasteController.php +++ b/src/Controller/PasteController.php @@ -6,7 +6,6 @@ namespace App\Controller; use App\Form\Type\PasteForm; use App\Entity\Paste; use App\Repository\PasteRepository; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; @@ -16,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request; class PasteController extends AbstractController { #[Route('/')] - public function new(Request $request, EntityManagerInterface $entityManager): Response { + public function new(Request $request, PasteRepository $pasteRepository): Response { $paste = new Paste(); $form = $this->createForm(PasteForm::class, $paste); @@ -30,8 +29,7 @@ class PasteController extends AbstractController $paste->setSecret(hash('sha1', random_bytes(25))); } - $entityManager->persist($paste); - $entityManager->flush(); + $pasteRepository->save($paste); return $this->redirectToRoute($request->attributes->get('_route')); diff --git a/src/Repository/PasteRepository.php b/src/Repository/PasteRepository.php index 12a8cb9..1065282 100644 --- a/src/Repository/PasteRepository.php +++ b/src/Repository/PasteRepository.php @@ -12,4 +12,10 @@ class PasteRepository extends ServiceEntityRepository public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Paste::class); } + + public function save(Paste $paste): void { + $entityManager = $this->getEntityManager(); + $entityManager->persist($paste); + $entityManager->flush(); + } } \ No newline at end of file