|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* File: GeneralConfigProvider.php |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maciej Sławik <[email protected]> |
|
9
|
|
|
* @copyright Copyright (C) 2019 Lizard Media (http://lizardmedia.pl) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LizardMedia\VarnishWarmer\Model\Config; |
|
13
|
|
|
|
|
14
|
|
|
use LizardMedia\VarnishWarmer\Api\Config\GeneralConfigProviderInterface; |
|
15
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class GeneralConfigProvider |
|
19
|
|
|
* @package LizardMedia\VarnishWarmer\Api\Config |
|
20
|
|
|
*/ |
|
21
|
|
|
class GeneralConfigProvider implements GeneralConfigProviderInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private const XML_PATH_CONCURRENT_REGENERATION = 'lm_varnish/general/max_concurrent_regeneration'; |
|
27
|
|
|
private const XML_PATH_CONCURRENT_PURGE = 'lm_varnish/general/max_concurrent_purge'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
private const REGENERATION_PROCESSES_DEFAULT = 10; |
|
33
|
|
|
private const REGENERATION_PROCESSES_MAX = 20; |
|
34
|
|
|
private const REGENERATION_PROCESSES_MIN = 1; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int |
|
38
|
|
|
*/ |
|
39
|
|
|
private const PURGE_PROCESSES_DEFAULT = 4; |
|
40
|
|
|
private const PURGE_PROCESSES_MAX = 20; |
|
41
|
|
|
private const PURGE_PROCESSES_MIN = 1; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var ScopeConfigInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
private $scopeConfig; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* GeneralConfigProvider constructor. |
|
50
|
|
|
* @param ScopeConfigInterface $scopeConfig |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(ScopeConfigInterface $scopeConfig) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->scopeConfig = $scopeConfig; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getMaxConcurrentRegenerationProcesses(): int |
|
61
|
|
|
{ |
|
62
|
|
|
$configValue = (int) $this->scopeConfig->getValue(self::XML_PATH_CONCURRENT_REGENERATION); |
|
63
|
|
|
return $this->isMaxRegenerationProcessesConfigValid($configValue) |
|
64
|
|
|
? $configValue |
|
65
|
|
|
: self::REGENERATION_PROCESSES_DEFAULT; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return int |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getMaxConcurrentPurgeProcesses(): int |
|
72
|
|
|
{ |
|
73
|
|
|
$configValue = (int) $this->scopeConfig->getValue(self::XML_PATH_CONCURRENT_PURGE); |
|
74
|
|
|
return $this->isMaxPurgeProcessesConfigValid($configValue) |
|
75
|
|
|
? $configValue |
|
76
|
|
|
: self::PURGE_PROCESSES_DEFAULT; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $configValue |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function isMaxRegenerationProcessesConfigValid(int $configValue): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return $configValue >= self::REGENERATION_PROCESSES_MIN && $configValue <= self::REGENERATION_PROCESSES_MAX; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param int $configValue |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function isMaxPurgeProcessesConfigValid(int $configValue): bool |
|
93
|
|
|
{ |
|
94
|
|
|
return $configValue >= self::PURGE_PROCESSES_MIN && $configValue <= self::PURGE_PROCESSES_MAX; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|