- md5
- a28ade182b15543a657e41073f7a4320
- sha1
- 68ec513454f86cf8e83aed1cb3ed9c886c36e78b
- sha256
- 17b60d8ea166be98ae1696e0328b73f97b287bec60a7d746113cd28cee0341f2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
<?php
/**
* @package Joomla.Plugin
* @subpackage System.sessiongc
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\SessionGC\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\MetadataManager;
use Joomla\Event\DispatcherInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Garbage collection handler for session related data
*
* @since 3.8.6
*/
final class SessionGC extends CMSPlugin
{
/**
* The meta data manager
*
* @var MetadataManager
*
* @since 5.0.0
*/
private $metadataManager;
/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param MetadataManager $metadataManager The user factory
*
* @since 5.0.0
*/
public function __construct(DispatcherInterface $dispatcher, array $config, MetadataManager $metadataManager)
{
parent::__construct($dispatcher, $config);
$this->metadataManager = $metadataManager;
}
/**
* Runs after the HTTP response has been sent to the client and performs garbage collection tasks
*
* @return void
*
* @since 3.8.6
*/
public function onAfterRespond()
{
if ($this->params->get('enable_session_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
$this->getApplication()->getSession()->gc();
}
}
if ($this->getApplication()->get('session_handler', 'none') !== 'database' && $this->params->get('enable_session_metadata_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
$this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire());
}
}
}
}
No other release has this exact content. See every version of this file.