Skip to content

Commit 58e9321

Browse files
committed
Fixed #866 // Deprecated Method Cassandra\ExecutionOptions starting of Cassandra 1.3
1 parent e0c8c61 commit 58e9321

File tree

3 files changed

+55
-31
lines changed

3 files changed

+55
-31
lines changed

lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ class Driver extends MasterSlaveReplicationDriver
3232
* @param AggregatablePoolInterface ...$driverPools
3333
* @throws ReflectionException
3434
*/
35-
public function __construct(string $clusterName, EventManagerInterface $em, AggregatablePoolInterface ...$driverPools)
36-
{
35+
public function __construct(
36+
string $clusterName,
37+
EventManagerInterface $em,
38+
AggregatablePoolInterface ...$driverPools
39+
) {
3740
/** Straight call to ClusterPoolAbstract constructor */
38-
(new ReflectionMethod(\get_parent_class(\get_parent_class($this)), __FUNCTION__))
39-
->invoke($this, $clusterName, $em, ...$driverPools);
41+
(new ReflectionMethod(
42+
\get_parent_class(\get_parent_class($this)),
43+
__FUNCTION__
44+
))->invoke($this, $clusterName, $em, ...$driverPools);
45+
4046
$randomPool = $driverPools[\random_int(0, \count($driverPools) - 1)];
4147

4248
$this->eventManager->dispatch(

lib/Phpfastcache/Drivers/Cassandra/Config.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,22 @@
2121

2222
class Config extends ConfigurationOption
2323
{
24-
/**
25-
* @var string
26-
*/
2724
protected string $host = '127.0.0.1';
28-
/**
29-
* @var int
30-
*/
25+
3126
protected int $port = 9042;
32-
/**
33-
* @var int
34-
*/
27+
3528
protected int $timeout = 2;
36-
/**
37-
* @var string
38-
*/
29+
3930
protected string $username = '';
40-
/**
41-
* @var string
42-
*/
31+
4332
protected string $password = '';
44-
/**
45-
* @var bool
46-
*/
33+
4734
protected bool $sslEnabled = false;
48-
/**
49-
* @var bool
50-
*/
35+
5136
protected bool $sslVerify = false;
52-
/**
53-
* @return string
54-
*/
37+
38+
protected bool $useLegacyExecutionOptions = false;
39+
5540
public function getHost(): string
5641
{
5742
return $this->host;
@@ -188,4 +173,24 @@ public function setSslVerify(bool $sslVerify): static
188173
$this->sslVerify = $sslVerify;
189174
return $this;
190175
}
176+
177+
/**
178+
* @return bool
179+
*/
180+
public function isUseLegacyExecutionOptions(): bool
181+
{
182+
return $this->useLegacyExecutionOptions;
183+
}
184+
185+
/**
186+
* @param bool $useLegacyExecutionOptions
187+
* @return $this
188+
* @throws PhpfastcacheLogicException
189+
*/
190+
public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static
191+
{
192+
$this->enforceLockedProperty(__FUNCTION__);
193+
$this->useLegacyExecutionOptions = $useLegacyExecutionOptions;
194+
return $this;
195+
}
191196
}

lib/Phpfastcache/Drivers/Cassandra/Driver.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function driverConnect(): bool
127127
protected function driverRead(ExtendedCacheItemInterface $item): ?array
128128
{
129129
try {
130-
$options = new Cassandra\ExecutionOptions(
130+
$options = $this->getCompatibleExecutionOptionsArgument(
131131
[
132132
'arguments' => ['cache_id' => $item->getKey()],
133133
'page_size' => 1,
@@ -161,7 +161,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
161161

162162
try {
163163
$cacheData = $this->encode($this->driverPreWrap($item));
164-
$options = new Cassandra\ExecutionOptions(
164+
$options = $this->getCompatibleExecutionOptionsArgument(
165165
[
166166
'arguments' => [
167167
'cache_uuid' => new Cassandra\Uuid(''),
@@ -214,7 +214,7 @@ protected function driverDelete(ExtendedCacheItemInterface $item): bool
214214
$this->assertCacheItemType($item, Item::class);
215215

216216
try {
217-
$options = new Cassandra\ExecutionOptions(
217+
$options = $this->getCompatibleExecutionOptionsArgument(
218218
[
219219
'arguments' => [
220220
'cache_id' => $item->getKey(),
@@ -304,4 +304,17 @@ public function getStats(): DriverStatistic
304304
->setData(implode(', ', array_keys($this->itemInstances)))
305305
->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.');
306306
}
307+
308+
/**
309+
* @param array<string, mixed> $options
310+
* @return array<string, mixed>|Cassandra\ExecutionOptions
311+
*/
312+
protected function getCompatibleExecutionOptionsArgument(array $options): mixed
313+
{
314+
if ($this->getConfig()->isUseLegacyExecutionOptions()) {
315+
return new Cassandra\ExecutionOptions($options);
316+
}
317+
318+
return $options;
319+
}
307320
}

0 commit comments

Comments
 (0)