diff --git a/src/Controller/BranchController.php b/src/Controller/BranchController.php index be05968..8e726e6 100644 --- a/src/Controller/BranchController.php +++ b/src/Controller/BranchController.php @@ -6,6 +6,7 @@ use App\Entity\Branch; use App\Entity\Message; use App\Form\CreateMessageType; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -14,8 +15,10 @@ use Symfony\Component\Routing\Attribute\Route; #[Route('/branches')] final class BranchController extends AbstractController { - public function __construct(private readonly EntityManagerInterface $entityManager) - { + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly LoggerInterface $logger, + ) { } #[Route('/{id}', name: 'branch', methods: ['GET'])] @@ -39,6 +42,12 @@ final class BranchController extends AbstractController $this->entityManager->persist($message); $this->entityManager->flush(); + $this->logger->info('Created message with id {messageId}', ['messageId' => $message->getId()]); + } else { + $this->logger->warning('Cant create message', [ + 'isFormSubmitted' => $form->isSubmitted(), + 'isFormValid' => $form->isValid(), + ]); } return $this->redirectToRoute('branch', ['id' => $branch->getId()]);