class UserRequestSubscriber in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/EventSubscriber/UserRequestSubscriber.php \Drupal\user\EventSubscriber\UserRequestSubscriber
Updates the current user's last access time.
Hierarchy
- class \Drupal\user\EventSubscriber\UserRequestSubscriber implements EventSubscriberInterface
Expanded class hierarchy of UserRequestSubscriber
1 string reference to 'UserRequestSubscriber'
- user.services.yml in core/
modules/ user/ user.services.yml - core/modules/user/user.services.yml
1 service uses UserRequestSubscriber
File
- core/
modules/ user/ src/ EventSubscriber/ UserRequestSubscriber.php, line 20 - Contains \Drupal\user\EventSubscriber\UserRequestSubscriber.
Namespace
Drupal\user\EventSubscriberView source
class UserRequestSubscriber implements EventSubscriberInterface {
/**
* The current account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a new UserRequestSubscriber.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager) {
$this->account = $account;
$this->entityManager = $entity_manager;
}
/**
* Updates the current user's last access time.
*
* @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event
* The event to process.
*/
public function onKernelTerminate(PostResponseEvent $event) {
if ($this->account
->isAuthenticated() && REQUEST_TIME - $this->account
->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
// Do that no more than once per 180 seconds.
/** @var \Drupal\user\UserStorageInterface $storage */
$storage = $this->entityManager
->getStorage('user');
$storage
->updateLastAccessTimestamp($this->account, REQUEST_TIME);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Should go before other subscribers start to write their caches. Notably
// before \Drupal\Core\EventSubscriber\KernelDestructionSubscriber to
// prevent instantiation of destructed services.
$events[KernelEvents::TERMINATE][] = [
'onKernelTerminate',
300,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserRequestSubscriber:: |
protected | property | The current account. | |
UserRequestSubscriber:: |
protected | property | The entity manager. | |
UserRequestSubscriber:: |
public static | function |
Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface:: |
|
UserRequestSubscriber:: |
public | function | Updates the current user's last access time. | |
UserRequestSubscriber:: |
public | function | Constructs a new UserRequestSubscriber. |