<?php
namespace App\Controller;
use App\Entity\DevLog;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/devlog")
*/
class DevLogController extends AbstractController
{
/**
* @Route("/", name="devlog")
*/
public function index(): Response
{
return new Response('');
}
/**
* @Route("/log", name="devlog_log", methods={"POST"})
*/
public function log(Request $request, EntityManagerInterface $entityManager){
$content=json_decode(($request->getContent() && !empty($request->getContent())) ? $request->getContent() : [],true);
$type=null;
if(isset($content['type'])){
$type=$content['type'];
}
$file=null;
if(isset($content['file'])){
$file=$content['file'];
}
$line=null;
if(isset($content['line'])){
$line=$content['line'];
}
$info=null;
if(isset($content['info'])){
$info=$content['info'];
}
$data=null;
if(isset($content['data'])){
$data=$content['data'];
}
$message=null;
if(isset($content['message'])){
$message=$content['message'];
}
$devLog = new DevLog();
$devLog->setAction('LOG')
->setType($type)
->setFile($file)
->setLine($line)
->setInfo($info)
->setData($data)
->setMessage($message)
->setAddDate(new \DateTime('now'));
$entityManager->persist($devLog);
$entityManager->flush();
return new Response('');
}
}