Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1382f51

Browse files
committedJul 7, 2022
feat(*): Prepare release 0.23.0
1 parent 77246ed commit 1382f51

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
 

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.23.0] - 2022-07-07
9+
10+
### Added
11+
- Add test configuration to mock IPs and proxy behavior
12+
813
## [0.22.1] - 2022-06-03
914

1015
### Fixed

‎src/ApiCache.php‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ private function saveRemediationsForCacheKey(array $decisions, string $cacheKey)
398398
/**
399399
* Cache key convention.
400400
*
401-
* @throws Exception
401+
* @param string $scope
402+
* @param string $value
403+
* @return string
402404
*/
403405
private function getCacheKey(string $scope, string $value): string
404406
{
@@ -638,7 +640,7 @@ public function clear(): bool
638640
*
639641
* @return array "count": number of decisions added, "errors": decisions not added
640642
*
641-
* @throws InvalidArgumentException
643+
* @throws InvalidArgumentException|\Psr\Cache\CacheException
642644
*/
643645
public function warmUp(): array
644646
{
@@ -968,7 +970,7 @@ private function getIpCachedVariables(string $cacheTag, string $ip)
968970
* @return array
969971
* @throws InvalidArgumentException
970972
*/
971-
public function getIpVariables($cacheTag, $names, $ip): array
973+
public function getIpVariables(string $cacheTag, array $names, string $ip): array
972974
{
973975
$cachedVariables = $this->getIpCachedVariables($cacheTag, $ip);
974976
$variables = [];
@@ -998,13 +1000,7 @@ public function setIpVariables(string $cacheTag, array $pairs, string $ip)
9981000
foreach ($pairs as $name => $value) {
9991001
$cachedVariables[$name] = $value;
10001002
}
1001-
$duration = (Constants::CACHE_TAG_CAPTCHA === $cacheTag)
1002-
? $this->cacheExpirationForCaptcha : $this->cacheExpirationForGeo;
1003-
$item = $this->adapter->getItem(base64_encode($cacheKey));
1004-
$item->set($cachedVariables);
1005-
$item->expiresAt(new DateTime("+$duration seconds"));
1006-
$item->tag($cacheTag);
1007-
$this->adapter->save($item);
1003+
$this->saveCacheItem($cacheTag, $cacheKey, $cachedVariables);
10081004
}
10091005

10101006
/**
@@ -1024,6 +1020,19 @@ public function unsetIpVariables(string $cacheTag, array $pairs, string $ip)
10241020
foreach ($pairs as $name => $value) {
10251021
unset($cachedVariables[$name]);
10261022
}
1023+
$this->saveCacheItem($cacheTag, $cacheKey, $cachedVariables);
1024+
}
1025+
1026+
/**
1027+
* @param string $cacheTag
1028+
* @param string $cacheKey
1029+
* @param $cachedVariables
1030+
* @return void
1031+
* @throws InvalidArgumentException
1032+
* @throws \Psr\Cache\CacheException
1033+
*/
1034+
protected function saveCacheItem(string $cacheTag, string $cacheKey, $cachedVariables): void
1035+
{
10271036
$duration = (Constants::CACHE_TAG_CAPTCHA === $cacheTag)
10281037
? $this->cacheExpirationForCaptcha : $this->cacheExpirationForGeo;
10291038
$item = $this->adapter->getItem(base64_encode($cacheKey));

‎src/Constants.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Constants
2020
public const DEFAULT_LAPI_URL = 'http://localhost:8080';
2121

2222
/** @var string The last version of this library */
23-
public const VERSION = 'v0.22.1';
23+
public const VERSION = 'v0.23.0';
2424

2525
/** @var string The user agent used to send request to LAPI */
2626
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/' . self::VERSION;
@@ -97,6 +97,6 @@ class Constants
9797
/** @var string The Maxmind "City" database type */
9898
public const MAXMIND_CITY = 'city';
9999

100-
/** @var string The "disabled" bouncing level */
100+
/** @var string The "disabled" x-forwarded-for setting */
101101
public const X_FORWARDED_DISABLED = 'no_forward';
102102
}

0 commit comments

Comments
 (0)
Please sign in to comment.