src/Controller/DevLogController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\DevLog;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. /**
  10.  * @Route("/devlog")
  11.  */
  12. class DevLogController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/", name="devlog")
  16.      */
  17.     public function index(): Response
  18.     {
  19.         return new Response('');
  20.     }
  21.     /**
  22.      * @Route("/log", name="devlog_log", methods={"POST"})
  23.      */
  24.     public function log(Request $requestEntityManagerInterface $entityManager){
  25.         $content=json_decode(($request->getContent() && !empty($request->getContent())) ? $request->getContent() : [],true);
  26.         $type=null;
  27.         if(isset($content['type'])){
  28.             $type=$content['type'];
  29.         }
  30.         $file=null;
  31.         if(isset($content['file'])){
  32.             $file=$content['file'];
  33.         }
  34.         $line=null;
  35.         if(isset($content['line'])){
  36.             $line=$content['line'];
  37.         }
  38.         $info=null;
  39.         if(isset($content['info'])){
  40.             $info=$content['info'];
  41.         }
  42.         $data=null;
  43.         if(isset($content['data'])){
  44.             $data=$content['data'];
  45.         }
  46.         $message=null;
  47.         if(isset($content['message'])){
  48.             $message=$content['message'];
  49.         }
  50.         $devLog = new DevLog();
  51.         $devLog->setAction('LOG')
  52.             ->setType($type)
  53.             ->setFile($file)
  54.             ->setLine($line)
  55.             ->setInfo($info)
  56.             ->setData($data)
  57.             ->setMessage($message)
  58.             ->setAddDate(new \DateTime('now'));
  59.         $entityManager->persist($devLog);
  60.         $entityManager->flush();
  61.         return new Response('');
  62.     }
  63. }