-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSessionManager.php
49 lines (45 loc) · 1.3 KB
/
SessionManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Authors: Alex Gusev <alex@flancer64.com>
* Since: 2018
*/
namespace Flancer32\BotSess\Plugin\Session;
/**
* Don't open sessions for crawlers/bots.
*/
class SessionManager
{
/** @var \Flancer32\BotSess\Helper\Filter */
private $hlp;
/** @var \Flancer32\BotSess\Logger */
private $logger;
public function __construct(
\Flancer32\BotSess\Logger $logger,
\Flancer32\BotSess\Helper\Filter $hlp
) {
$this->logger = $logger;
$this->hlp = $hlp;
}
public function aroundStart(
\Magento\Framework\Session\SessionManager $subject,
\Closure $proceed
) {
$result = $subject;
if (isset($_SERVER['REMOTE_ADDR'])) {
/* filter HTTP requests only */
$isBot = $this->hlp->isBot();
if (!$isBot) {
/* proceed with session start */
$result = $proceed();
} else {
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'n/a';
$address = $_SERVER['REMOTE_ADDR'];
$this->logger->debug("Skip session for agent |$agent| from $address.");
}
} else {
/* process CLI & cron requests */
$result = $proceed();
}
return $result;
}
}