Search
 
SCRIPT & CODE EXAMPLE
 

PHP

symfony user online

<?php

namespace AppEventSubscriber;

use SymfonyComponentEventDispatcherEventSubscriberInterface;
use SymfonyComponentHttpKernelKernelEvents;
use DoctrineORMEntityManagerInterface;
use SymfonyComponentSecurityCoreSecurity;

class ActivitySubscriber implements EventSubscriberInterface {

    private $em;
    private $security;

    public function __construct(
    EntityManagerInterface $em, Security $security) {
        $this->em = $em;
        $this->security = $security;
    }

    public function onTerminate() {
        $user = $this->security->getUser();

        if (!$user->isActiveNow()) {
            $user->setLastActivityAt(new DateTime());
            $this->em->flush($user);
        }
    }

    public static function getSubscribedEvents() {
        return [
            // must be registered before (i.e. with a higher priority than) the default Locale listener
            KernelEvents::TERMINATE => [['onTerminate', 20]],
        ];
    }

}
Comment

PREVIOUS NEXT
Code Example
Php :: imagelib thourgh class in codeigniter 
Php :: string replace in php 
Php :: onbeforeunload com mysql php 
Php :: Wonder Gallery WordPress plugin php code to display a gallery 
Php :: laravel How to query foreign relations data along with multiple main records 
Php :: php sum 2 arrays 
Php :: show all custom taxonomy term & title with filter hook 
Php :: creating unique number adding zero 0 in number 
Php :: session flash data (old input) 
Php :: Php countup from a date 
Php :: order table in laravel 
Php :: wp_remote_post decode data 
Php :: remove the public from url in laravel 
Php :: file viewer codeigniter 
Php :: Lumen framework promise 
Php :: laravel livewire refresh computed property 
Php :: Laravel retrieving aggregates 
Php :: how to check if page is opened by bot 
Php :: Regenerate session ID and remove all session data 
Php :: laravel seeder with relationship 
Php :: Delete Collection (Get) 
Php :: php browser cache clear 
Php :: siteurl 
Php :: not have permision elgg settings.php 
Php :: laravel collect whereNotIn not working 
Php :: how do istart writing a php code 
Php :: PHP wordwrap — Wraps a string to a given number of characters 
Php :: custom middleware laravel 8 
Php :: laravel pdf generator 
Php :: spatie media library 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =