Skip to content

Commit 5f3cae8

Browse files
committed
Improved support of driverReadMultiple for Firestore
1 parent 4c8a107 commit 5f3cae8

16 files changed

+231
-99
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ before_install:
5252
#- "yes | (./vendor/bin/ci-pecl-install mongodb) || echo \"PECL Mongodb install failed\"" # Mongodb seems to be provided In Bionic: https://docs.travis-ci.com/user/reference/bionic/#php-support
5353
# - "yes | ./vendor/bin/ci-pecl-install apcu || echo \"PECL Apcu install failed\"" # Apcu seems to be provided In Bionic: https://docs.travis-ci.com/user/reference/bionic/#php-support
5454
- "yes | ./vendor/bin/ci-pecl-install memcache || echo \"PECL Memcache install failed\""
55+
- "yes | ./vendor/bin/ci-pecl-install memcached || echo \"PECL Memcached install failed\""
5556
- "yes | ./vendor/bin/ci-pecl-install couchbase-3.2.2 couchbase || echo \"PECL Couchbase install failed\"" # @todo UPGRADE TO COUCHBASE 4.x.x once we upgraded from Bionic to Focal
5657
- phpenv config-add bin/ci/php_common.ini
5758
- phpenv config-rm xdebug.ini

bin/ci/scripts/install_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ composer install
66
#####
77
# Travis CI have php mongodb extension locked to 1.10, so we must set the mongodb/mongodb minimum version to 1.9 :(
88
#####
9-
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.20 solarium/solarium:~6.1
9+
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.39 solarium/solarium:~6.1

lib/Phpfastcache/CacheManager.php

+1-20
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
9898
$driverClass = $driver;
9999
} else {
100100
$driver = self::normalizeDriverName($driver);
101-
$driverClass = self::validateDriverClass(self::getDriverClass($driver));
101+
$driverClass = self::getDriverClass($driver);
102102
}
103103
$config = self::validateConfig($config);
104104
$instanceId = $instanceId ?: self::getInstanceHash($driverClass, $config);
@@ -170,25 +170,6 @@ public static function normalizeDriverName(string $driverName): string
170170
return \ucfirst(\strtolower(\trim($driverName)));
171171
}
172172

173-
/**
174-
* @param string $driverClass
175-
* @return string
176-
* @throws PhpfastcacheDriverException
177-
*/
178-
protected static function validateDriverClass(string $driverClass): string
179-
{
180-
if (!\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
181-
throw new PhpfastcacheDriverException(
182-
\sprintf(
183-
'Class "%s" does not implement "%s"',
184-
$driverClass,
185-
ExtendedCacheItemPoolInterface::class
186-
)
187-
);
188-
}
189-
return $driverClass;
190-
}
191-
192173
/**
193174
* @param string $driverName
194175
* @return string

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public function getAllItems(string $pattern = ''): iterable
4646
$this->eventManager->dispatch(Event::CACHE_GET_ALL_ITEMS, $this, new EventReferenceParameter($driverReadAllKeysCallback));
4747
$keys = $driverReadAllKeysCallback($pattern);
4848

49-
if ((is_array($keys) && $keys !== []) || is_countable($keys) && count($keys) > 0) {
50-
return $this->getItems($keys);
49+
if (count($keys) > 0) {
50+
return $this->getItems($keys instanceof \Traversable ? iterator_to_array($keys) : $keys);
5151
}
5252

5353
return [];

lib/Phpfastcache/Drivers/Arangodb/Config.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getDatabase(): string
7070
/**
7171
* @throws PhpfastcacheLogicException
7272
*/
73-
public function setDatabase(string $database): Config
73+
public function setDatabase(string $database): static
7474
{
7575
return $this->setProperty('database', $database);
7676
}
@@ -83,7 +83,7 @@ public function getCollection(): string
8383
/**
8484
* @throws PhpfastcacheLogicException
8585
*/
86-
public function setCollection(string $collection): Config
86+
public function setCollection(string $collection): static
8787
{
8888
return $this->setProperty('collection', $collection);
8989
}
@@ -98,10 +98,9 @@ public function getEndpoint(): string|array
9898

9999
/**
100100
* @param string|array<string> $endpoint
101-
* @return $this
102101
* @throws PhpfastcacheLogicException
103102
*/
104-
public function setEndpoint(string|array $endpoint): Config
103+
public function setEndpoint(string|array $endpoint): static
105104
{
106105
return $this->setProperty('endpoint', $endpoint);
107106
}
@@ -114,7 +113,7 @@ public function getConnection(): string
114113
/**
115114
* @throws PhpfastcacheLogicException
116115
*/
117-
public function setConnection(string $connection): Config
116+
public function setConnection(string $connection): static
118117
{
119118
return $this->setProperty('connection', $connection);
120119
}
@@ -127,7 +126,7 @@ public function getAuthType(): string
127126
/**
128127
* @throws PhpfastcacheLogicException
129128
*/
130-
public function setAuthType(string $authType): Config
129+
public function setAuthType(string $authType): static
131130
{
132131
return $this->setProperty('authType', $authType);
133132
}
@@ -140,7 +139,7 @@ public function getAuthUser(): string
140139
/**
141140
* @throws PhpfastcacheLogicException
142141
*/
143-
public function setAuthUser(string $authUser): Config
142+
public function setAuthUser(string $authUser): static
144143
{
145144
return $this->setProperty('authUser', $authUser);
146145
}
@@ -153,7 +152,7 @@ public function getAuthPasswd(): string
153152
/**
154153
* @throws PhpfastcacheLogicException
155154
*/
156-
public function setAuthPasswd(string $authPasswd): Config
155+
public function setAuthPasswd(string $authPasswd): static
157156
{
158157
return $this->setProperty('authPasswd', $authPasswd);
159158
}
@@ -168,10 +167,9 @@ public function getAuthJwt(): ?string
168167

169168
/**
170169
* @param string|null $authJwt
171-
* @return Config
172170
* @throws PhpfastcacheLogicException
173171
*/
174-
public function setAuthJwt(?string $authJwt): Config
172+
public function setAuthJwt(?string $authJwt): static
175173
{
176174
return $this->setProperty('authJwt', $authJwt);
177175
}
@@ -184,7 +182,7 @@ public function isAutoCreate(): bool
184182
/**
185183
* @throws PhpfastcacheLogicException
186184
*/
187-
public function setAutoCreate(bool $autoCreate): Config
185+
public function setAutoCreate(bool $autoCreate): static
188186
{
189187
return $this->setProperty('autoCreate', $autoCreate);
190188
}
@@ -197,7 +195,7 @@ public function getConnectTimeout(): int
197195
/**
198196
* @throws PhpfastcacheLogicException
199197
*/
200-
public function setConnectTimeout(int $connectTimeout): Config
198+
public function setConnectTimeout(int $connectTimeout): static
201199
{
202200
return $this->setProperty('connectTimeout', $connectTimeout);
203201
}
@@ -210,7 +208,7 @@ public function getRequestTimeout(): int
210208
/**
211209
* @throws PhpfastcacheLogicException
212210
*/
213-
public function setRequestTimeout(int $requestTimeout): Config
211+
public function setRequestTimeout(int $requestTimeout): static
214212
{
215213
return $this->setProperty('requestTimeout', $requestTimeout);
216214
}
@@ -223,7 +221,7 @@ public function getUpdatePolicy(): string
223221
/**
224222
* @throws PhpfastcacheLogicException
225223
*/
226-
public function setUpdatePolicy(string $updatePolicy): Config
224+
public function setUpdatePolicy(string $updatePolicy): static
227225
{
228226
return $this->setProperty('updatePolicy', $updatePolicy);
229227
}
@@ -236,7 +234,7 @@ public function isVerifyCert(): bool
236234
/**
237235
* @throws PhpfastcacheLogicException
238236
*/
239-
public function setVerifyCert(bool $verifyCert): Config
237+
public function setVerifyCert(bool $verifyCert): static
240238
{
241239
return $this->setProperty('verifyCert', $verifyCert);
242240
}
@@ -249,7 +247,7 @@ public function isSelfSigned(): bool
249247
/**
250248
* @throws PhpfastcacheLogicException
251249
*/
252-
public function setSelfSigned(bool $selfSigned): Config
250+
public function setSelfSigned(bool $selfSigned): static
253251
{
254252
return $this->setProperty('selfSigned', $selfSigned);
255253
}
@@ -262,7 +260,7 @@ public function getCiphers(): string
262260
/**
263261
* @throws PhpfastcacheLogicException
264262
*/
265-
public function setCiphers(string $ciphers): Config
263+
public function setCiphers(string $ciphers): static
266264
{
267265
return $this->setProperty('ciphers', $ciphers);
268266
}
@@ -277,10 +275,9 @@ public function getTraceFunction(): ?\Closure
277275

278276
/**
279277
* @param \Closure|null $traceFunction
280-
* @return Config
281278
* @throws PhpfastcacheLogicException
282279
*/
283-
public function setTraceFunction(?\Closure $traceFunction): Config
280+
public function setTraceFunction(?\Closure $traceFunction): static
284281
{
285282
return $this->setProperty('traceFunction', $traceFunction);
286283
}

lib/Phpfastcache/Drivers/Cassandra/Config.php

-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function getHost(): string
4444

4545
/**
4646
* @param string $host
47-
* @return self
4847
* @throws PhpfastcacheLogicException
4948
*/
5049
public function setHost(string $host): static
@@ -62,7 +61,6 @@ public function getPort(): int
6261

6362
/**
6463
* @param int $port
65-
* @return self
6664
* @throws PhpfastcacheLogicException
6765
*/
6866
public function setPort(int $port): static
@@ -80,7 +78,6 @@ public function getTimeout(): int
8078

8179
/**
8280
* @param int $timeout
83-
* @return self
8481
* @throws PhpfastcacheLogicException
8582
*/
8683
public function setTimeout(int $timeout): static
@@ -98,7 +95,6 @@ public function getUsername(): string
9895

9996
/**
10097
* @param string $username
101-
* @return self
10298
* @throws PhpfastcacheLogicException
10399
*/
104100
public function setUsername(string $username): static
@@ -116,7 +112,6 @@ public function getPassword(): string
116112

117113
/**
118114
* @param string $password
119-
* @return self
120115
* @throws PhpfastcacheLogicException
121116
*/
122117
public function setPassword(string $password): static
@@ -134,7 +129,6 @@ public function isSslEnabled(): bool
134129

135130
/**
136131
* @param bool $sslEnabled
137-
* @return self
138132
* @throws PhpfastcacheLogicException
139133
*/
140134
public function setSslEnabled(bool $sslEnabled): static
@@ -152,7 +146,6 @@ public function isSslVerify(): bool
152146

153147
/**
154148
* @param bool $sslVerify
155-
* @return self
156149
* @throws PhpfastcacheLogicException
157150
*/
158151
public function setSslVerify(bool $sslVerify): static
@@ -170,7 +163,6 @@ public function isUseLegacyExecutionOptions(): bool
170163

171164
/**
172165
* @param bool $useLegacyExecutionOptions
173-
* @return $this
174166
* @throws PhpfastcacheLogicException
175167
*/
176168
public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static

lib/Phpfastcache/Drivers/Firestore/Config.php

+66-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@
2626
*/
2727
class Config extends ConfigurationOption
2828
{
29+
protected int $batchSize = 100;
2930
protected ?string $googleCloudProject = null;
3031
protected ?string $googleApplicationCredential = null;
3132
protected bool $allowEnvCredentialOverride = false;
32-
protected string $collection;
33+
protected string $collectionName = 'phpfastcache';
34+
35+
/**
36+
* @see \Google\Cloud\Firestore\FirestoreClient::DEFAULT_DATABASE
37+
*/
38+
protected string $databaseName = '(default)';
3339

3440
/**
3541
* @inheritDoc
@@ -41,24 +47,79 @@ public function __construct(array $parameters = [])
4147
$this->googleApplicationCredential = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_APPLICATION_CREDENTIALS');
4248
}
4349

50+
public function getBatchSize(): int
51+
{
52+
return $this->batchSize;
53+
}
54+
55+
public function setBatchSize(int $batchSize): Config
56+
{
57+
return $this->setProperty('batchSize', $batchSize);
58+
}
59+
4460
/**
4561
* @return string
62+
* @deprecated As of 9.2, will be removed in v10.
63+
* @see self::getCollectionName()
4664
*/
4765
public function getCollection(): string
4866
{
49-
return $this->collection;
67+
return $this->collectionName;
68+
}
69+
70+
/**
71+
* @param string $collectionName
72+
* @return Config
73+
* @throws PhpfastcacheLogicException
74+
* @see self::setCollectionName()
75+
* @deprecated As of 9.2, will be removed in v10.
76+
*/
77+
public function setCollection(string $collectionName): Config
78+
{
79+
if (isset($this->collectionName) && $collectionName !== $this->collectionName) {
80+
trigger_error('getCollection/setCollection methods are deprecated, use getCollectionName/setCollectionName instead', E_USER_DEPRECATED);
81+
}
82+
return $this->setProperty('collectionName', $collectionName);
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
public function getCollectionName(): string
89+
{
90+
return $this->collectionName;
5091
}
5192

5293
/**
53-
* @param string $collection
94+
* @param string $collectionName
5495
* @return Config
5596
* @throws PhpfastcacheLogicException
5697
*/
57-
public function setCollection(string $collection): Config
98+
public function setCollectionName(string $collectionName): Config
99+
{
100+
return $this->setProperty('collectionName', $collectionName);
101+
}
102+
103+
/**
104+
* @return string
105+
*/
106+
public function getDatabaseName(): string
58107
{
59-
return $this->setProperty('collection', $collection);
108+
return $this->databaseName;
60109
}
61110

111+
/**
112+
* @param string $databaseName
113+
* @return Config
114+
* @throws PhpfastcacheLogicException
115+
*/
116+
public function setDatabaseName(string $databaseName): Config
117+
{
118+
return $this->setProperty('databaseName', $databaseName);
119+
}
120+
121+
122+
62123
/**
63124
* @return string|null
64125
*/

0 commit comments

Comments
 (0)