Skip to content

Commit 4006b84

Browse files
authored
Merge pull request #854 from PHPSocialNetwork/v9
Released 9.0.2
2 parents bcd068f + 467cbb9 commit 4006b84

19 files changed

+507
-96
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ cache:
2222
- $HOME/pecl_cache
2323
php:
2424
- 8.0
25-
# - 8.1 # Uncomment this when 8.1 will be released
25+
- 8.1
2626
# - nightly # nightly is currently too much unstable many bundled extension are not available...
2727
jobs:
2828
fast_finish: true
2929
allow_failures:
30+
- php: 8.1 # PHP 8.1 is still unstable ATM
3031
- php: nightly
3132

3233
before_install:

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 9.0.2
2+
##### 04 march 2022
3+
- __Core__
4+
- Updated CacheContract::__invoke() signature
5+
- Added new option to allow EventManager override + improved EventManager tests (EventManager::setInstance())
6+
- __Drivers__
7+
- Fixed #853 // Configuration validation issue with Memcached socket (path)
8+
- __Misc__
9+
- Fixed typo and some types hint
10+
111
## 9.0.1
212
##### 14 november 2021
313
- __Core__
@@ -6,6 +16,7 @@
616
- `\Psr\Cache\CacheItemInterface::set` will also no longer accepts resource object anymore as method unique parameter
717
- __Misc__
818
- Fixed typos in [README.md](./README.md)
19+
920
## 9.0.0
1021
##### 31 october 2021
1122
- __Migration guide__

lib/Phpfastcache/CacheContract.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ public function __construct(CacheItemPoolInterface $cacheInstance)
2929
}
3030

3131
/**
32-
* @param string $cacheKey
33-
* @param callable $callback
34-
* @param DateInterval|integer|null $expiresAfter
35-
* @return mixed
3632
* @throws InvalidArgumentException
3733
*/
3834
public function get(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
3935
{
4036
$cacheItem = $this->cacheInstance->getItem($cacheKey);
4137

42-
if (! $cacheItem->isHit()) {
38+
if (!$cacheItem->isHit()) {
4339
/*
4440
* Parameter $cacheItem will be available as of 8.0.6
4541
*/
@@ -54,8 +50,11 @@ public function get(string $cacheKey, callable $callback, DateInterval|int $expi
5450
return $cacheItem->get();
5551
}
5652

57-
public function __invoke(...$args): mixed
53+
/**
54+
* @throws InvalidArgumentException
55+
*/
56+
public function __invoke(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
5857
{
59-
return $this->get(...$args);
58+
return $this->get($cacheKey, $callback, $expiresAfter);
6059
}
6160
}

lib/Phpfastcache/Config/ConfigurationOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function setSuperGlobalAccessor(?object $superGlobalAccessor): static
332332
*/
333333
protected function getDefaultSuperGlobalAccessor(): \Closure
334334
{
335-
return \Closure::fromCallable(static function (string $superGlobalName, ?string $keyName = null) {
335+
return \Closure::fromCallable(static function (string $superGlobalName, ?string $keyName = null): string|int|float|array|bool|null {
336336
return match ($superGlobalName) {
337337
'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER,
338338
'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST,

lib/Phpfastcache/Core/Item/CacheItemTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function expiresAfter(int|\DateInterval|null $time): static
119119
if (\is_numeric($time)) {
120120
if ($time <= 0) {
121121
/**
122-
* 5 years, however memcached or memory cached will gone when u restart it
122+
* 5 years, however memcached or memory cached will be gone when u restart it
123123
* just recommended for sqlite. files
124124
*/
125125
$time = 30 * 24 * 3600 * 5;

lib/Phpfastcache/Drivers/Memcache/Config.php

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Phpfastcache\Drivers\Memcache;
1717

1818
use Phpfastcache\Config\ConfigurationOption;
19+
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
1920
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
2021
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
2122

@@ -27,10 +28,10 @@ class Config extends ConfigurationOption
2728
* Multiple server can be added this way:
2829
* $cfg->setServers([
2930
* [
31+
* // If you use an UNIX socket set the host and port to null
3032
* 'host' => '127.0.0.1',
33+
* //'path' => 'path/to/unix/socket',
3134
* 'port' => 11211,
32-
* 'saslUser' => false,
33-
* 'saslPassword' => false,
3435
* ]
3536
* ]);
3637
*/
@@ -40,49 +41,6 @@ class Config extends ConfigurationOption
4041

4142
protected int $port = 11211;
4243

43-
protected string $saslUser = '';
44-
45-
protected string $saslPassword = '';
46-
47-
/**
48-
* @return string
49-
*/
50-
public function getSaslUser(): string
51-
{
52-
return $this->saslUser;
53-
}
54-
55-
/**
56-
* @param string $saslUser
57-
* @return self
58-
* @throws PhpfastcacheLogicException
59-
*/
60-
public function setSaslUser(string $saslUser): static
61-
{
62-
$this->enforceLockedProperty(__FUNCTION__);
63-
$this->saslUser = $saslUser;
64-
return $this;
65-
}
66-
67-
/**
68-
* @return string
69-
*/
70-
public function getSaslPassword(): string
71-
{
72-
return $this->saslPassword;
73-
}
74-
75-
/**
76-
* @param string $saslPassword
77-
* @return self
78-
* @throws PhpfastcacheLogicException
79-
*/
80-
public function setSaslPassword(string $saslPassword): static
81-
{
82-
$this->enforceLockedProperty(__FUNCTION__);
83-
$this->saslPassword = $saslPassword;
84-
return $this;
85-
}
8644

8745
/**
8846
* @return array
@@ -95,8 +53,6 @@ public function getServers(): array
9553
'host' => $this->getHost(),
9654
'path' => $this->getPath(),
9755
'port' => $this->getPort(),
98-
'saslUser' => $this->getSaslUser() ?: false,
99-
'saslPassword' => $this->getSaslPassword() ?: false,
10056
],
10157
];
10258
}
@@ -109,23 +65,41 @@ public function getServers(): array
10965
* @return self
11066
* @throws PhpfastcacheInvalidConfigurationException
11167
* @throws PhpfastcacheLogicException
68+
*
69+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
70+
* @SuppressWarnings(PHPMD.NPathComplexity)
11271
*/
11372
public function setServers(array $servers): static
11473
{
11574
$this->enforceLockedProperty(__FUNCTION__);
11675
foreach ($servers as $server) {
117-
if ($diff = array_diff(['host', 'port', 'saslUser', 'saslPassword'], array_keys($server))) {
118-
throw new PhpfastcacheInvalidConfigurationException('Missing keys for memcached server: ' . implode(', ', $diff));
76+
if (\array_key_exists('saslUser', $server) || array_key_exists('saslPassword', $server)) {
77+
throw new PhpfastcacheInvalidConfigurationException('Unlike Memcached, Memcache does not support SASL authentication');
11978
}
120-
if ($diff = array_diff(array_keys($server), ['host', 'port', 'saslUser', 'saslPassword'])) {
79+
80+
if ($diff = array_diff(array_keys($server), ['host', 'port', 'path'])) {
12181
throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: ' . implode(', ', $diff));
12282
}
123-
if (!is_string($server['host'])) {
124-
throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array');
83+
84+
if (!empty($server['host']) && !empty($server['path'])) {
85+
throw new PhpfastcacheInvalidConfigurationException('Host and path cannot be simultaneous defined.');
86+
}
87+
88+
if ((isset($server['host']) && !is_string($server['host'])) || (empty($server['path']) && empty($server['host']))) {
89+
throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array if path is not defined');
90+
}
91+
92+
if ((isset($server['path']) && !is_string($server['path'])) || (empty($server['host']) && empty($server['path']))) {
93+
throw new PhpfastcacheInvalidConfigurationException('Path must be a valid string in "$server" configuration array if host is not defined');
12594
}
126-
if (!is_int($server['port'])) {
95+
96+
if (!empty($server['host']) && (empty($server['port']) || !is_int($server['port'])|| $server['port'] < 1)) {
12797
throw new PhpfastcacheInvalidConfigurationException('Port must be a valid integer in "$server" configuration array');
12898
}
99+
100+
if (!empty($server['port']) && !empty($server['path'])) {
101+
throw new PhpfastcacheInvalidConfigurationException('Port should not be defined along with path');
102+
}
129103
}
130104
$this->servers = $servers;
131105
return $this;
@@ -148,6 +122,7 @@ public function setHost(string $host): static
148122
{
149123
$this->enforceLockedProperty(__FUNCTION__);
150124
$this->host = $host;
125+
151126
return $this;
152127
}
153128

lib/Phpfastcache/Drivers/Memcache/Driver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ public function getStats(): DriverStatistic
9898
protected function driverConnect(): bool
9999
{
100100
$this->instance = new MemcacheSoftware();
101-
$servers = $this->getConfig()->getServers();
102101

103-
foreach ($servers as $server) {
102+
foreach ($this->getConfig()->getServers() as $server) {
104103
try {
105104
/**
106105
* If path is provided we consider it as a UNIX Socket

lib/Phpfastcache/Drivers/Memcached/Config.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class Config extends ConfigurationOption
2727
* Multiple server can be added this way:
2828
* $cfg->setServers([
2929
* [
30+
* // If you use an UNIX socket set the host and port to null
3031
* 'host' => '127.0.0.1',
32+
* //'path' => 'path/to/unix/socket',
3133
* 'port' => 11211,
32-
* 'saslUser' => false,
33-
* 'saslPassword' => false,
34+
* 'saslUser' => null,
35+
* 'saslPassword' => null,
3436
* ]
3537
* ]);
3638
*/
@@ -97,8 +99,8 @@ public function getServers(): array
9799
'host' => $this->getHost(),
98100
'path' => $this->getPath(),
99101
'port' => $this->getPort(),
100-
'saslUser' => $this->getSaslUser() ?: false,
101-
'saslPassword' => $this->getSaslPassword() ?: false,
102+
'saslUser' => $this->getSaslUser() ?: null,
103+
'saslPassword' => $this->getSaslPassword() ?: null,
102104
],
103105
];
104106
}
@@ -111,23 +113,41 @@ public function getServers(): array
111113
* @return self
112114
* @throws PhpfastcacheInvalidConfigurationException
113115
* @throws PhpfastcacheLogicException
116+
*
117+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
118+
* @SuppressWarnings(PHPMD.NPathComplexity)
114119
*/
115120
public function setServers(array $servers): static
116121
{
117122
$this->enforceLockedProperty(__FUNCTION__);
118123
foreach ($servers as $server) {
119-
if ($diff = array_diff(['host', 'port', 'saslUser', 'saslPassword'], array_keys($server))) {
120-
throw new PhpfastcacheInvalidConfigurationException('Missing keys for memcached server: ' . implode(', ', $diff));
121-
}
122-
if ($diff = array_diff(array_keys($server), ['host', 'port', 'saslUser', 'saslPassword'])) {
124+
if ($diff = array_diff(array_keys($server), ['host', 'port', 'saslUser', 'saslPassword', 'path'])) {
123125
throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: ' . implode(', ', $diff));
124126
}
125-
if (!is_string($server['host'])) {
126-
throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array');
127+
128+
if (!empty($server['host']) && !empty($server['path'])) {
129+
throw new PhpfastcacheInvalidConfigurationException('Host and path cannot be simultaneous defined.');
130+
}
131+
132+
if ((isset($server['host']) && !is_string($server['host'])) || (empty($server['path']) && empty($server['host']))) {
133+
throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array if path is not defined');
134+
}
135+
136+
if ((isset($server['path']) && !is_string($server['path'])) || (empty($server['host']) && empty($server['path']))) {
137+
throw new PhpfastcacheInvalidConfigurationException('Path must be a valid string in "$server" configuration array if host is not defined');
127138
}
128-
if (!is_int($server['port'])) {
139+
140+
if (!empty($server['host']) && (empty($server['port']) || !is_int($server['port'])|| $server['port'] < 1)) {
129141
throw new PhpfastcacheInvalidConfigurationException('Port must be a valid integer in "$server" configuration array');
130142
}
143+
144+
if (!empty($server['port']) && !empty($server['path'])) {
145+
throw new PhpfastcacheInvalidConfigurationException('Port should not be defined along with path');
146+
}
147+
148+
if (!empty($server['saslUser']) && !empty($server['saslPassword']) && (!is_string($server['saslUser']) || !is_string($server['saslPassword']))) {
149+
throw new PhpfastcacheInvalidConfigurationException('If provided, saslUser and saslPassword must be a string');
150+
}
131151
}
132152
$this->servers = $servers;
133153
return $this;

lib/Phpfastcache/Drivers/Memcached/Driver.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ protected function driverConnect(): bool
104104
$this->instance->setOption(MemcachedSoftware::OPT_PREFIX_KEY, $optPrefix);
105105
}
106106

107-
$servers = $this->getConfig()->getServers();
108-
109-
foreach ($servers as $server) {
107+
foreach ($this->getConfig()->getServers() as $server) {
110108
$connected = false;
111109
/**
112110
* If path is provided we consider it as an UNIX Socket

lib/Phpfastcache/Event/EventManagerInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ interface EventManagerInterface
5252
*/
5353
public static function getInstance(): static;
5454

55+
/**
56+
* @param EventManagerInterface $eventManagerInstance
57+
* @return void
58+
*/
59+
public static function setInstance(EventManagerInterface $eventManagerInstance): void;
60+
5561
/**
5662
* @param string $eventName
5763
* @param array ...$args

0 commit comments

Comments
 (0)