Piou-piou /
RibsAdminBundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace PiouPiou\RibsAdminBundle\Service; |
||||
| 4 | |||||
| 5 | use Doctrine\ORM\EntityManagerInterface; |
||||
| 6 | use PiouPiou\RibsAdminBundle\Entity\UserLogs; |
||||
| 7 | use Symfony\Component\HttpKernel\Event\RequestEvent; |
||||
| 8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
||||
| 9 | |||||
| 10 | class UserLog |
||||
| 11 | { |
||||
| 12 | /** |
||||
| 13 | * @var TokenStorageInterface |
||||
| 14 | */ |
||||
| 15 | private $token_storage; |
||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * @var EntityManagerInterface a |
||||
| 19 | */ |
||||
| 20 | private $em; |
||||
| 21 | |||||
| 22 | public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em) |
||||
| 23 | { |
||||
| 24 | $this->token_storage = $token_storage; |
||||
| 25 | $this->em = $em; |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @param RequestEvent $request_event |
||||
| 30 | */ |
||||
| 31 | public function onKernelRequest(RequestEvent $request_event) |
||||
| 32 | { |
||||
| 33 | if ($request_event->isMasterRequest()) { |
||||
| 34 | $user = null; |
||||
| 35 | if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) { |
||||
| 36 | $user = $this->token_storage->getToken()->getUser()->getUser(); |
||||
| 37 | } |
||||
| 38 | $request = $request_event->getRequest(); |
||||
| 39 | $route = $request->get("_route"); |
||||
| 40 | |||||
| 41 | if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt", "ribsadmin_userlogs", "ribsadmin_userlogs_show"])) { |
||||
| 42 | return; |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | if ($user) { |
||||
| 46 | $user_log = new UserLogs(); |
||||
| 47 | $user_log->setMethod($request->getMethod()); |
||||
| 48 | $user_log->setUser($user); |
||||
| 49 | $user_log->setRoute($request->get("_route")); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 50 | $user_log->setUrl($request->getRequestUri()); |
||||
| 51 | $user_log->setFullUrl($request->getUri()); |
||||
| 52 | $user_log->setRequestFormat($request->getRequestFormat()); |
||||
|
0 ignored issues
–
show
It seems like
$request->getRequestFormat() can also be of type null; however, parameter $request_format of PiouPiou\RibsAdminBundle...ogs::setRequestFormat() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 53 | $user_log->setRequestParameters($request->request->all()); |
||||
| 54 | $this->em->persist($user_log); |
||||
| 55 | $this->em->flush(); |
||||
| 56 | } |
||||
| 57 | } |
||||
| 58 | } |
||||
| 59 | } |
||||
| 60 |