1 | <?php |
||
32 | class Driver implements ExtendedCacheItemPoolInterface |
||
33 | { |
||
34 | use DriverBaseTrait; |
||
35 | |||
36 | /** |
||
37 | * @var \CouchbaseBucket[] |
||
38 | */ |
||
39 | protected $bucketInstances = []; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $bucketCurrent = ''; |
||
45 | |||
46 | /** |
||
47 | * Driver constructor. |
||
48 | * @param array $config |
||
49 | * @throws phpFastCacheDriverException |
||
50 | */ |
||
51 | public function __construct(array $config = []) |
||
61 | |||
62 | /** |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function driverCheck() |
||
69 | |||
70 | /** |
||
71 | * @param \Psr\Cache\CacheItemInterface $item |
||
72 | * @return mixed |
||
73 | * @throws phpFastCacheInvalidArgumentException |
||
74 | */ |
||
75 | protected function driverWrite(CacheItemInterface $item) |
||
86 | |||
87 | /** |
||
88 | * @param \Psr\Cache\CacheItemInterface $item |
||
89 | * @return null|array |
||
90 | */ |
||
91 | protected function driverRead(CacheItemInterface $item) |
||
102 | |||
103 | /** |
||
104 | * @param \Psr\Cache\CacheItemInterface $item |
||
105 | * @return bool |
||
106 | * @throws phpFastCacheInvalidArgumentException |
||
107 | */ |
||
108 | protected function driverDelete(CacheItemInterface $item) |
||
119 | |||
120 | /** |
||
121 | * @return bool |
||
122 | */ |
||
123 | protected function driverClear() |
||
127 | |||
128 | /** |
||
129 | * @return bool |
||
130 | * @throws phpFastCacheLogicException |
||
131 | */ |
||
132 | protected function driverConnect() |
||
133 | { |
||
134 | if ($this->instance instanceof CouchbaseClient) { |
||
135 | throw new phpFastCacheLogicException('Already connected to Couchbase server'); |
||
136 | } else { |
||
137 | |||
138 | |||
139 | $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
||
140 | $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : 8091; |
||
141 | $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
||
142 | $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
||
143 | $buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [ |
||
144 | [ |
||
145 | 'bucket' => 'default', |
||
146 | 'password' => '', |
||
147 | ], |
||
148 | ]; |
||
149 | |||
150 | $this->instance = new CouchbaseClient("couchbase://{$host}:{$port}", $username, $password); |
||
151 | |||
152 | foreach ($buckets as $bucket) { |
||
153 | $this->bucketCurrent = $this->bucketCurrent ?: $bucket[ 'bucket' ]; |
||
154 | $this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ], $bucket[ 'password' ])); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | return true; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @return \CouchbaseBucket |
||
163 | */ |
||
164 | protected function getBucket() |
||
168 | |||
169 | /** |
||
170 | * @param $bucketName |
||
171 | * @param \CouchbaseBucket $CouchbaseBucket |
||
172 | * @throws phpFastCacheLogicException |
||
173 | */ |
||
174 | protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket) |
||
182 | |||
183 | /******************** |
||
184 | * |
||
185 | * PSR-6 Extended Methods |
||
186 | * |
||
187 | *******************/ |
||
188 | |||
189 | /** |
||
190 | * @return DriverStatistic |
||
191 | */ |
||
192 | public function getStats() |
||
203 | } |