src/Subscriber/EventSubscriber/Request/RequestSubscriber.php line 49
<?phpnamespace App\Subscriber\EventSubscriber\Request;use App\Entity\System\Log\RequestLog;use App\Security\AppCustomAuthenticator;use App\Services\Php\System\GlobalFunctions;use App\Services\Php\System\SystemService;use App\Services\Php\Traits\LoggedDataTrait;use Doctrine\ORM\EntityManager;use Psr\Container\ContainerInterface;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Session\SessionInterface;use Symfony\Component\HttpKernel\Event\RequestEvent;use Symfony\Component\HttpKernel\KernelEvents;use Symfony\Component\Security\Http\Util\TargetPathTrait;use Symfony\Component\Security\Csrf\CsrfToken;class RequestSubscriber implements EventSubscriberInterface{use TargetPathTrait;use LoggedDataTrait;private $container;private $em;private $ss;public function __construct(ContainerInterface $container){$this->container = $container;$this->em = $this->container->get('doctrine')->getManager();}public static function getSubscribedEvents(){return [RequestEvent::class => 'onKernelRequest',];}/*** @Security("user.isEnabled()")*/public function onKernelRequest(RequestEvent $event): void{$gf = new GlobalFunctions();$request = $event->getRequest();if (!$event->isMainRequest()|| $request->isXmlHttpRequest()|| AppCustomAuthenticator::LOGIN_ROUTE === $request->attributes->get('_route')) {return;}return;$request = $event->getRequest();$queryDATA = array();foreach ($request->query->all() as $key => $query) {if (is_array($query)) {foreach ($query as $arrayKey => $q) {if (is_array($q)) {foreach ($q as $key2 => $s) {if (is_array($s)) {foreach ($s as $key3 => $t) {$tc = $gf->xss_clean($t);$queryDATA[$key][$arrayKey][$key2][$key3] = $tc;}} else {$sc = $gf->xss_clean($s);$queryDATA[$key][$arrayKey][$key2] = $sc;}}} else {$qc = $gf->xss_clean($q);$queryDATA[$key][$arrayKey] = $qc;}}} else {$query = $gf->xss_clean($query);$queryDATA[$key] = $query;}}$request->query->replace($queryDATA);$postDATA = array();foreach ($request->request->all() as $key => $post_data) {if (is_array($post_data)) {foreach ($post_data as $arrayKey => $q) {if (is_array($q)) {foreach ($q as $key2 => $s) {if (is_array($s)) {foreach ($s as $key3 => $t) {$tc = $gf->xss_clean($t);$postDATA[$key][$arrayKey][$key2][$key3] = $tc;}} else {$sc = $gf->xss_clean($s);$postDATA[$key][$arrayKey][$key2] = $sc;}}} else {$qc = $gf->xss_clean($q);$postDATA[$key][$arrayKey] = $qc;}}} else {$post_data = $gf->xss_clean($post_data);$postDATA[$key] = $post_data;}}$request->request->replace($postDATA);$status = 0;if ($event->isMainRequest()) {$controller = $event->getRequest()->attributes->get("_controller");$explodeController = explode("\\", $controller);$explodeControllerNameAndFunction = explode("::", end($explodeController));$controller_path = $explodeControllerNameAndFunction[0];$controller_function = $explodeControllerNameAndFunction[1];if ($controller_path and $controller_function and $status = 1) {$disabled_url_path = array("",);// $security = $this->container->get('security.cont');// $user = $security->getToken()->getUser();$ip_address = $this->get_ip_address();$method = $event->getRequest()->getMethod();$url = $event->getRequest()->getPathInfo();$controller_name = explode("\\", $controller_path);$bundle = $controller_name[0];$controller = end($controller_name);$url = str_replace(strtolower($bundle) . "/", "", ltrim(rtrim($url, "/"), "/"));$url = ltrim($url, '/');$localhost = 1;if ($this->getLoggedUser(1) and $this->getLoggedUser() != "anon."and $this->getLoggedUser() > 0and ($ip_address != "127.0.0.1" or $localhost == 1) and (!in_array($url, $disabled_url_path) and strpos($url, "favicon.ico") === false)) {$sub_user_id = $this->getLoggedUser();$user_id = $this->getKullanici();if ($user_id == $sub_user_id) $sub_user_id = null;$methodID = 0;if ($method === "GET") $methodID = 1;if ($method === "POST") $methodID = 2;$queryDATA = array();foreach ($event->getRequest()->query->all() as $key => $q) {if ($q != "*" and $q != "") $queryDATA["get"][$key] = $q;}foreach ($event->getRequest()->request->all() as $key => $q) {if ($q != "*" and $q != "") $queryDATA["post"][$key] = $q;}/** @var EntityManager $em */$em = $this->em;if ($ip_address == null) {$ip_address = $event->getRequest()->getClientIp();}$adminLog = new RequestLog();$adminLog->setBusinessId($user_id);$adminLog->setUserId($user_id);$adminLog->setCreatedAt(new \DateTime("now"));$adminLog->setIp($ip_address);$adminLog->setMethod($methodID);$adminLog->setUrlPath($url);$adminLog->setQuerys($queryDATA);$em->persist($adminLog);$em->flush();}}}$this->saveTargetPath($request->getSession(), 'main', $request->getUri());}}