WIP: feature_paste #1

Draft
Miroslavsckaya wants to merge 24 commits from feature_paste into master
2 changed files with 8 additions and 4 deletions
Showing only changes of commit 561b016e38 - Show all commits

View file

@ -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('/')]
Review

I'd suggest explicitly defining which request methods we're processing here.

P.S. We'll move this to YAML in the end.

I'd suggest explicitly defining which request methods we're processing here. P.S. We'll move this to YAML in the end.
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'));

View file

@ -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();
}
}