Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,15 @@ jobs:
- 6379:6379

strategy:
fail-fast: false
matrix:
include:
# 7.x configurations
- php-version: 7.3
use-lowest-dependencies: true
shared-test-version: 4.x-dev
- php-version: 7.3
use-lowest-dependencies: false
shared-test-version: 4.x-dev

- php-version: 7.4
use-lowest-dependencies: true
shared-test-version: 4.x-dev
- php-version: 7.4
use-lowest-dependencies: false
shared-test-version: 4.x-dev

# 8.0 configurations
- php-version: 8.0
use-lowest-dependencies: true
shared-test-version: 4.x-dev
- php-version: 8.0
use-lowest-dependencies: false
shared-test-version: 5.x-dev

# 8.1 configurations
- php-version: 8.1
use-lowest-dependencies: true
shared-test-version: 4.x-dev
- php-version: 8.1
use-lowest-dependencies: false
shared-test-version: 5.x-dev
- php-version: 8.1
use-lowest-dependencies: false
use-lowest-dependencies: true
shared-test-version: dev-main

# 8.2 configurations
Expand All @@ -64,6 +39,14 @@ jobs:
use-lowest-dependencies: false
shared-test-version: dev-main

# 8.3 configurations
- php-version: 8.3
use-lowest-dependencies: false
shared-test-version: 5.x-dev
- php-version: 8.3
use-lowest-dependencies: false
shared-test-version: dev-main

steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs/build
docs/.phpdoc
phpunit/
.phpunit.result.cache
.php-cs-fixer.cache
15 changes: 15 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$finder = PhpCsFixer\Finder::create()->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config
->setFinder($finder)
->setUsingCache(true)
->setRules([
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'ordered_imports' => true,
'no_unused_imports' => true,
'array_syntax' => ['syntax' => 'short'],
]);
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: help
help: #! Show this help message
@echo 'Usage: make [target] ... '
@echo ''
@echo 'Targets:'
@grep -h -F '#!' $(MAKEFILE_LIST) | grep -v grep | sed 's/:.*#!/:/' | column -t -s":"

.PHONY: test
test: #! Run unit tests
php -d xdebug.mode=coverage vendor/bin/phpunit

.PHONY: coverage
coverage: #! Run unit tests with test coverage
php -d xdebug.mode=coverage vendor/bin/phpunit

.PHONY: lint
lint: #! Run quality control tools (e.g. psalm)
./vendor/bin/psalm --no-cache
composer cs-check
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
}
],
"require": {
"php": ">=7.3",
"launchdarkly/server-sdk": ">=4.0.0 <7.0.0"
"php": ">=8.1",
"ext-redis": "*",
"launchdarkly/server-sdk": ">=6.3.0 <7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^9"
"friendsofphp/php-cs-fixer": "^3.68",
"phpunit/php-code-coverage": "^9",
"phpunit/phpunit": "^9",
"vimeo/psalm": "^5"
},
"autoload": {
"psr-4": {
Expand All @@ -38,5 +42,9 @@
},
"config": {
"sort-packages": true
},
"scripts": {
"cs-check": "vendor/bin/php-cs-fixer fix --diff --dry-run --verbose --config=.php-cs-fixer.php",
"cs-fix": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php-cs-fixer.php"
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
55 changes: 26 additions & 29 deletions src/LaunchDarkly/Impl/Integrations/PHPRedisFeatureRequester.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<?php

namespace LaunchDarkly\Impl\Integrations;

use LaunchDarkly\Impl\Integrations\FeatureRequesterBase;
use Redis;

/**
* @internal
*/
class PHPRedisFeatureRequester extends FeatureRequesterBase
{
/** @var array */
private $_redisOptions;
/** @var \Redis */
private $_redisInstance;
/** @var string */
private $_prefix;
private ?array $redisOptions = null;
private ?Redis $redisInstance = null;
private ?string $prefix;

public function __construct($baseUri, $sdkKey, $options)
public function __construct(string $baseUri, string $sdkKey, array $options)
{
parent::__construct($baseUri, $sdkKey, $options);

$this->_prefix = $options['redis_prefix'] ?? null;
if ($this->_prefix === null || $this->_prefix === '') {
$this->_prefix = 'launchdarkly';
/** @var ?string **/
$this->prefix = $options['redis_prefix'] ?? null;
if ($this->prefix === null || $this->prefix === '') {
$this->prefix = 'launchdarkly';
}

/** @var ?Redis */
$client = $this->_options['phpredis_client'] ?? null;
if ($client instanceof \Redis) {
$this->_redisInstance = $client;
if ($client instanceof Redis) {
$this->redisInstance = $client;
} else {
$this->_redisOptions = [
$this->redisOptions = [
"timeout" => $options['redis_timeout'] ?? 5,
"host" => $options['redis_host'] ?? 'localhost',
"port" => $options['redis_port'] ?? 6379,
Expand All @@ -40,37 +40,34 @@ public function __construct($baseUri, $sdkKey, $options)
protected function readItemString(string $namespace, string $key): ?string
{
$redis = $this->getConnection();
return $redis->hget("$this->_prefix:$namespace", $key);
return $redis->hget("$this->prefix:$namespace", $key);
}

protected function readItemStringList(string $namespace): ?array
{
$redis = $this->getConnection();
$raw = $redis->hgetall("$this->_prefix:$namespace");
$raw = $redis->hgetall("$this->prefix:$namespace");
return $raw ? array_values($raw) : null;
}

/**
* @return \Redis
*/
protected function getConnection()
protected function getConnection(): Redis
{
if ($this->_redisInstance instanceof \Redis) {
return $this->_redisInstance;
if ($this->redisInstance instanceof Redis) {
return $this->redisInstance;
}

$redis = new \Redis();
$redis = new Redis();
$redis->pconnect(
$this->_redisOptions["host"],
$this->_redisOptions["port"],
$this->_redisOptions["timeout"],
$this->redisOptions["host"],
$this->redisOptions["port"],
$this->redisOptions["timeout"],
'launchdarkly/php-server-sdk-redis-phpredis'
);

if ($this->_redisOptions['password']) {
$redis->auth($this->_redisOptions['password']);
if ($this->redisOptions['password']) {
$redis->auth($this->redisOptions['password']);
}

return $this->_redisInstance = $redis;
return $this->redisInstance = $redis;
}
}
5 changes: 3 additions & 2 deletions src/LaunchDarkly/Integrations/PHPRedis.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace LaunchDarkly\Integrations;

use LaunchDarkly\Impl\Integrations\PHPRedisFeatureRequester;
Expand Down Expand Up @@ -32,13 +33,13 @@ class PHPRedis
* - `apc_expiration`: expiration time in seconds for local caching, if `APCu` is installed
* @return mixed an object to be stored in the `feature_requester` configuration property
*/
public static function featureRequester($options = array())
public static function featureRequester($options = [])
{
if (!extension_loaded('redis')) {
throw new \RuntimeException("phpredis extension is required to use Integrations\\PHPRedis");
}

return function ($baseUri, $sdkKey, $baseOptions) use ($options) {
return function (string $baseUri, string $sdkKey, array $baseOptions) use ($options) {
return new PHPRedisFeatureRequester($baseUri, $sdkKey, array_merge($baseOptions, $options));
};
}
Expand Down
2 changes: 0 additions & 2 deletions tests/PHPRedisFeatureRequesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace LaunchDarkly\Impl\Integrations\Tests;

use LaunchDarkly\Impl\Integrations\PHPRedisFeatureRequester;
use LaunchDarkly\Integrations\PHPRedis;
use LaunchDarkly\SharedTest\DatabaseFeatureRequesterTestBase;
use \Redis;

class PHPRedisFeatureRequesterTest extends DatabaseFeatureRequesterTestBase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPRedisFeatureRequesterWithClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace LaunchDarkly\Impl\Integrations\Tests;

use \Redis;
use LaunchDarkly\Impl\Integrations\PHPRedisFeatureRequester;
use LaunchDarkly\Integrations\PHPRedis;
use LaunchDarkly\SharedTest\DatabaseFeatureRequesterTestBase;
use \Redis;

class PHPRedisFeatureRequesterWithClientTest extends DatabaseFeatureRequesterTestBase
{
Expand Down
Loading