1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* File: PurgingConfigProvider.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\PurgingConfigProviderInterface; |
15
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class PurgingConfigProvider |
19
|
|
|
* @package LizardMedia\VarnishWarmer\Api\Config |
20
|
|
|
*/ |
21
|
|
|
class PurgingConfigProvider implements PurgingConfigProviderInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private const XML_PATH_USE_CUSTOM_HOST = 'lm_varnish/purge/different_purge_host'; |
27
|
|
|
private const XML_PATH_CUSTOM_HOST = 'lm_varnish/purge/custom_host'; |
28
|
|
|
private const XML_PATH_CUSTOM_HEADER_HOST = 'lm_varnish/purge/header_host'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private const PURGE_HOSTS_DELIMITER = ','; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ScopeConfigInterface |
37
|
|
|
*/ |
38
|
|
|
private $scopeConfig; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* GeneralConfigProvider constructor. |
42
|
|
|
* @param ScopeConfigInterface $scopeConfig |
43
|
|
|
*/ |
44
|
|
|
public function __construct(ScopeConfigInterface $scopeConfig) |
45
|
|
|
{ |
46
|
|
|
$this->scopeConfig = $scopeConfig; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function isPurgeCustomHostEnabled(): bool |
53
|
|
|
{ |
54
|
|
|
return (bool) $this->scopeConfig->getValue(self::XML_PATH_USE_CUSTOM_HOST); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function getCustomPurgeHosts(): array |
61
|
|
|
{ |
62
|
|
|
$hostsFieldValue = (string)$this->scopeConfig->getValue(self::XML_PATH_CUSTOM_HOST); |
63
|
|
|
return explode(self::PURGE_HOSTS_DELIMITER, $hostsFieldValue); |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getAdditionalHostForHeader(): string |
71
|
|
|
{ |
72
|
|
|
return (string) $this->scopeConfig->getValue(self::XML_PATH_CUSTOM_HEADER_HOST); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|