Skip to content

Commit

Permalink
Fixed #866 // Deprecated Method Cassandra\ExecutionOptions starting o…
Browse files Browse the repository at this point in the history
…f Cassandra 1.3
  • Loading branch information
Geolim4 committed May 24, 2022
1 parent e0c8c61 commit 58e9321
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
14 changes: 10 additions & 4 deletions lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ class Driver extends MasterSlaveReplicationDriver
* @param AggregatablePoolInterface ...$driverPools
* @throws ReflectionException
*/
public function __construct(string $clusterName, EventManagerInterface $em, AggregatablePoolInterface ...$driverPools)
{
public function __construct(
string $clusterName,
EventManagerInterface $em,
AggregatablePoolInterface ...$driverPools
) {
/** Straight call to ClusterPoolAbstract constructor */
(new ReflectionMethod(\get_parent_class(\get_parent_class($this)), __FUNCTION__))
->invoke($this, $clusterName, $em, ...$driverPools);
(new ReflectionMethod(
\get_parent_class(\get_parent_class($this)),
__FUNCTION__
))->invoke($this, $clusterName, $em, ...$driverPools);

$randomPool = $driverPools[\random_int(0, \count($driverPools) - 1)];

$this->eventManager->dispatch(
Expand Down
53 changes: 29 additions & 24 deletions lib/Phpfastcache/Drivers/Cassandra/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,22 @@

class Config extends ConfigurationOption
{
/**
* @var string
*/
protected string $host = '127.0.0.1';
/**
* @var int
*/

protected int $port = 9042;
/**
* @var int
*/

protected int $timeout = 2;
/**
* @var string
*/

protected string $username = '';
/**
* @var string
*/

protected string $password = '';
/**
* @var bool
*/

protected bool $sslEnabled = false;
/**
* @var bool
*/

protected bool $sslVerify = false;
/**
* @return string
*/

protected bool $useLegacyExecutionOptions = false;

public function getHost(): string
{
return $this->host;
Expand Down Expand Up @@ -188,4 +173,24 @@ public function setSslVerify(bool $sslVerify): static
$this->sslVerify = $sslVerify;
return $this;
}

/**
* @return bool
*/
public function isUseLegacyExecutionOptions(): bool
{
return $this->useLegacyExecutionOptions;
}

/**
* @param bool $useLegacyExecutionOptions
* @return $this
* @throws PhpfastcacheLogicException
*/
public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static
{
$this->enforceLockedProperty(__FUNCTION__);
$this->useLegacyExecutionOptions = $useLegacyExecutionOptions;
return $this;
}
}
19 changes: 16 additions & 3 deletions lib/Phpfastcache/Drivers/Cassandra/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function driverConnect(): bool
protected function driverRead(ExtendedCacheItemInterface $item): ?array
{
try {
$options = new Cassandra\ExecutionOptions(
$options = $this->getCompatibleExecutionOptionsArgument(
[
'arguments' => ['cache_id' => $item->getKey()],
'page_size' => 1,
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool

try {
$cacheData = $this->encode($this->driverPreWrap($item));
$options = new Cassandra\ExecutionOptions(
$options = $this->getCompatibleExecutionOptionsArgument(
[
'arguments' => [
'cache_uuid' => new Cassandra\Uuid(''),
Expand Down Expand Up @@ -214,7 +214,7 @@ protected function driverDelete(ExtendedCacheItemInterface $item): bool
$this->assertCacheItemType($item, Item::class);

try {
$options = new Cassandra\ExecutionOptions(
$options = $this->getCompatibleExecutionOptionsArgument(
[
'arguments' => [
'cache_id' => $item->getKey(),
Expand Down Expand Up @@ -304,4 +304,17 @@ public function getStats(): DriverStatistic
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.');
}

/**
* @param array<string, mixed> $options
* @return array<string, mixed>|Cassandra\ExecutionOptions
*/
protected function getCompatibleExecutionOptionsArgument(array $options): mixed
{
if ($this->getConfig()->isUseLegacyExecutionOptions()) {
return new Cassandra\ExecutionOptions($options);
}

return $options;
}
}

0 comments on commit 58e9321

Please sign in to comment.