-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.php
More file actions
83 lines (66 loc) · 2.89 KB
/
Settings.php
File metadata and controls
83 lines (66 loc) · 2.89 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Cleantalk\PHPAntiCrawler;
class Settings
{
/** @var string */
public const VERSION = 'phpanticrawler-1.0.36';
/** @var string */
public static $dbPath = __DIR__ . '/anticrawler.sqlite';
/** @var string */
public static $apiKey = '';
/** @var int */
public static $minSyncInterval = 60 * 10; // Ten minutes
/** @var int */
public static $maxSyncInterval = 60 * 60; // One hour
/** @var int */
public static $visitorForgetAfter = 60 * 60 * 24 * 30; // One month
/** @var int */
public static $maxRowsBeforeSync = 20000;
/** @var bool */
public static $syncByCron = false;
/** @var string */
public static $requestsBackend = 'sqlite';
/** @var string */
public static $keyDbHost = '127.0.0.1';
/** @var int */
public static $keyDbPort = 6379;
/** @var float */
public static $keyDbTimeout = 1.5;
/** @var string */
public static $keyDbPassword = '';
/** @var int */
public static $keyDbDatabase = 0;
/** @var string */
public static $keyDbPrefix = 'anticrawler';
/**
* Configures library settings. This method is called from the CleanTalkAntiCrawler constructor.
* Array values override config values.
*
* @param $options List of options
*
* Example:
* $ac = new CleanTalkAntiCrawler([
* 'max_sync_interval' => 60 * 10,
* 'max_rows_before_sync' => 10000,
* ]);
*/
public static function configure(array $options): void
{
if (!empty($options)) {
self::$dbPath = $options['db_path'] ?? self::$dbPath;
self::$apiKey = $options['api_key'] ?? self::$apiKey;
self::$minSyncInterval = $options['min_sync_interval'] ?? self::$minSyncInterval;
self::$maxSyncInterval = $options['max_sync_interval'] ?? self::$maxSyncInterval;
self::$visitorForgetAfter = $options['visitor_forget_after'] ?? self::$visitorForgetAfter;
self::$maxRowsBeforeSync = $options['max_rows_before_sync'] ?? self::$maxRowsBeforeSync;
self::$syncByCron = $options['sync_by_cron'] ?? self::$syncByCron;
self::$requestsBackend = $options['requests_backend'] ?? self::$requestsBackend;
self::$keyDbHost = $options['keydb_host'] ?? self::$keyDbHost;
self::$keyDbPort = $options['keydb_port'] ?? self::$keyDbPort;
self::$keyDbTimeout = $options['keydb_timeout'] ?? self::$keyDbTimeout;
self::$keyDbPassword = $options['keydb_password'] ?? self::$keyDbPassword;
self::$keyDbDatabase = $options['keydb_database'] ?? self::$keyDbDatabase;
self::$keyDbPrefix = $options['keydb_prefix'] ?? self::$keyDbPrefix;
}
}
}