-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCacheConfig.php
130 lines (109 loc) · 2.53 KB
/
CacheConfig.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace PayU\PaymentGateway\Model;
use PayU\PaymentGateway\Api\PayUCacheConfigInterface;
use Magento\Framework\Filesystem;
/**
* Class CacheConfig
* @package PayU\PaymentGateway\Model
*/
class CacheConfig implements PayUCacheConfigInterface
{
/**
* @var \OpenPayU_Configuration
*/
private $openPayUConfig;
/**
* @var string
*/
private $cacheDirectory;
/**
* @var string
*/
private $memCacheHost;
/**
* @var string
*/
private $memCachePort;
/**
* @var int
*/
private $memCacheWeight;
/**
* @var Filesystem
*/
private $fileSystem;
/**
* CacheConfig constructor.
*
* @param \OpenPayU_Configuration $openPayUConfig
* @param Filesystem $fileSystem
*/
public function __construct(\OpenPayU_Configuration $openPayUConfig, Filesystem $fileSystem)
{
$this->openPayUConfig = $openPayUConfig;
$this->fileSystem = $fileSystem;
$this->setDefaultConfig();
}
/**
* {@inheritdoc}
*/
public function setType($type)
{
$config = $this->openPayUConfig;
if ($type === PayUCacheConfigInterface::TYPE_FILE) {
$config::setOauthTokenCache(new \OauthCacheFile($this->cacheDirectory));
}
if ($type === PayUCacheConfigInterface::TYPE_MEMCACHE) {
$config::setOauthTokenCache(
new \OauthCacheMemcached($this->memCacheHost, $this->memCachePort, $this->memCacheWeight)
);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function setDirectory($directory)
{
$this->cacheDirectory = $directory;
return $this;
}
/**
* {@inheritdoc}
*/
public function setMemCacheHost($host)
{
$this->memCacheHost = $host;
return $this;
}
/**
* {@inheritdoc}
*/
public function setMemCachePort($port)
{
$this->memCachePort = $port;
return $this;
}
/**
* {@inheritdoc}
*/
public function setMemCacheWeight($weight)
{
$this->memCacheWeight = $weight;
return $this;
}
/**
* Set Default Config
*
* @return void
*/
private function setDefaultConfig()
{
$cacheDir = $this->fileSystem->getDirectoryRead('cache')->getAbsolutePath();
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$this->setDirectory($cacheDir);
$this->setType(PayUCacheConfigInterface::TYPE_FILE);
}
}