Skip to content

Commit

Permalink
Improved support of driverReadMultiple for Firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Dec 17, 2023
1 parent 4c8a107 commit 5f3cae8
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 99 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ before_install:
#- "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
# - "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
- "yes | ./vendor/bin/ci-pecl-install memcache || echo \"PECL Memcache install failed\""
- "yes | ./vendor/bin/ci-pecl-install memcached || echo \"PECL Memcached install failed\""
- "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
- phpenv config-add bin/ci/php_common.ini
- phpenv config-rm xdebug.ini
Expand Down
2 changes: 1 addition & 1 deletion bin/ci/scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ composer install
#####
# Travis CI have php mongodb extension locked to 1.10, so we must set the mongodb/mongodb minimum version to 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.20 solarium/solarium:~6.1
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
21 changes: 1 addition & 20 deletions lib/Phpfastcache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
$driverClass = $driver;
} else {
$driver = self::normalizeDriverName($driver);
$driverClass = self::validateDriverClass(self::getDriverClass($driver));
$driverClass = self::getDriverClass($driver);
}
$config = self::validateConfig($config);
$instanceId = $instanceId ?: self::getInstanceHash($driverClass, $config);
Expand Down Expand Up @@ -170,25 +170,6 @@ public static function normalizeDriverName(string $driverName): string
return \ucfirst(\strtolower(\trim($driverName)));
}

/**
* @param string $driverClass
* @return string
* @throws PhpfastcacheDriverException
*/
protected static function validateDriverClass(string $driverClass): string
{
if (!\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
throw new PhpfastcacheDriverException(
\sprintf(
'Class "%s" does not implement "%s"',
$driverClass,
ExtendedCacheItemPoolInterface::class
)
);
}
return $driverClass;
}

/**
* @param string $driverName
* @return string
Expand Down
4 changes: 2 additions & 2 deletions lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function getAllItems(string $pattern = ''): iterable
$this->eventManager->dispatch(Event::CACHE_GET_ALL_ITEMS, $this, new EventReferenceParameter($driverReadAllKeysCallback));
$keys = $driverReadAllKeysCallback($pattern);

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

return [];
Expand Down
35 changes: 16 additions & 19 deletions lib/Phpfastcache/Drivers/Arangodb/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getDatabase(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setDatabase(string $database): Config
public function setDatabase(string $database): static
{
return $this->setProperty('database', $database);
}
Expand All @@ -83,7 +83,7 @@ public function getCollection(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setCollection(string $collection): Config
public function setCollection(string $collection): static
{
return $this->setProperty('collection', $collection);
}
Expand All @@ -98,10 +98,9 @@ public function getEndpoint(): string|array

/**
* @param string|array<string> $endpoint
* @return $this
* @throws PhpfastcacheLogicException
*/
public function setEndpoint(string|array $endpoint): Config
public function setEndpoint(string|array $endpoint): static
{
return $this->setProperty('endpoint', $endpoint);
}
Expand All @@ -114,7 +113,7 @@ public function getConnection(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setConnection(string $connection): Config
public function setConnection(string $connection): static
{
return $this->setProperty('connection', $connection);
}
Expand All @@ -127,7 +126,7 @@ public function getAuthType(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setAuthType(string $authType): Config
public function setAuthType(string $authType): static
{
return $this->setProperty('authType', $authType);
}
Expand All @@ -140,7 +139,7 @@ public function getAuthUser(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setAuthUser(string $authUser): Config
public function setAuthUser(string $authUser): static
{
return $this->setProperty('authUser', $authUser);
}
Expand All @@ -153,7 +152,7 @@ public function getAuthPasswd(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setAuthPasswd(string $authPasswd): Config
public function setAuthPasswd(string $authPasswd): static
{
return $this->setProperty('authPasswd', $authPasswd);
}
Expand All @@ -168,10 +167,9 @@ public function getAuthJwt(): ?string

/**
* @param string|null $authJwt
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setAuthJwt(?string $authJwt): Config
public function setAuthJwt(?string $authJwt): static
{
return $this->setProperty('authJwt', $authJwt);
}
Expand All @@ -184,7 +182,7 @@ public function isAutoCreate(): bool
/**
* @throws PhpfastcacheLogicException
*/
public function setAutoCreate(bool $autoCreate): Config
public function setAutoCreate(bool $autoCreate): static
{
return $this->setProperty('autoCreate', $autoCreate);
}
Expand All @@ -197,7 +195,7 @@ public function getConnectTimeout(): int
/**
* @throws PhpfastcacheLogicException
*/
public function setConnectTimeout(int $connectTimeout): Config
public function setConnectTimeout(int $connectTimeout): static
{
return $this->setProperty('connectTimeout', $connectTimeout);
}
Expand All @@ -210,7 +208,7 @@ public function getRequestTimeout(): int
/**
* @throws PhpfastcacheLogicException
*/
public function setRequestTimeout(int $requestTimeout): Config
public function setRequestTimeout(int $requestTimeout): static
{
return $this->setProperty('requestTimeout', $requestTimeout);
}
Expand All @@ -223,7 +221,7 @@ public function getUpdatePolicy(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setUpdatePolicy(string $updatePolicy): Config
public function setUpdatePolicy(string $updatePolicy): static
{
return $this->setProperty('updatePolicy', $updatePolicy);
}
Expand All @@ -236,7 +234,7 @@ public function isVerifyCert(): bool
/**
* @throws PhpfastcacheLogicException
*/
public function setVerifyCert(bool $verifyCert): Config
public function setVerifyCert(bool $verifyCert): static
{
return $this->setProperty('verifyCert', $verifyCert);
}
Expand All @@ -249,7 +247,7 @@ public function isSelfSigned(): bool
/**
* @throws PhpfastcacheLogicException
*/
public function setSelfSigned(bool $selfSigned): Config
public function setSelfSigned(bool $selfSigned): static
{
return $this->setProperty('selfSigned', $selfSigned);
}
Expand All @@ -262,7 +260,7 @@ public function getCiphers(): string
/**
* @throws PhpfastcacheLogicException
*/
public function setCiphers(string $ciphers): Config
public function setCiphers(string $ciphers): static
{
return $this->setProperty('ciphers', $ciphers);
}
Expand All @@ -277,10 +275,9 @@ public function getTraceFunction(): ?\Closure

/**
* @param \Closure|null $traceFunction
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setTraceFunction(?\Closure $traceFunction): Config
public function setTraceFunction(?\Closure $traceFunction): static
{
return $this->setProperty('traceFunction', $traceFunction);
}
Expand Down
8 changes: 0 additions & 8 deletions lib/Phpfastcache/Drivers/Cassandra/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function getHost(): string

/**
* @param string $host
* @return self
* @throws PhpfastcacheLogicException
*/
public function setHost(string $host): static
Expand All @@ -62,7 +61,6 @@ public function getPort(): int

/**
* @param int $port
* @return self
* @throws PhpfastcacheLogicException
*/
public function setPort(int $port): static
Expand All @@ -80,7 +78,6 @@ public function getTimeout(): int

/**
* @param int $timeout
* @return self
* @throws PhpfastcacheLogicException
*/
public function setTimeout(int $timeout): static
Expand All @@ -98,7 +95,6 @@ public function getUsername(): string

/**
* @param string $username
* @return self
* @throws PhpfastcacheLogicException
*/
public function setUsername(string $username): static
Expand All @@ -116,7 +112,6 @@ public function getPassword(): string

/**
* @param string $password
* @return self
* @throws PhpfastcacheLogicException
*/
public function setPassword(string $password): static
Expand All @@ -134,7 +129,6 @@ public function isSslEnabled(): bool

/**
* @param bool $sslEnabled
* @return self
* @throws PhpfastcacheLogicException
*/
public function setSslEnabled(bool $sslEnabled): static
Expand All @@ -152,7 +146,6 @@ public function isSslVerify(): bool

/**
* @param bool $sslVerify
* @return self
* @throws PhpfastcacheLogicException
*/
public function setSslVerify(bool $sslVerify): static
Expand All @@ -170,7 +163,6 @@ public function isUseLegacyExecutionOptions(): bool

/**
* @param bool $useLegacyExecutionOptions
* @return $this
* @throws PhpfastcacheLogicException
*/
public function setUseLegacyExecutionOptions(bool $useLegacyExecutionOptions): static
Expand Down
71 changes: 66 additions & 5 deletions lib/Phpfastcache/Drivers/Firestore/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@
*/
class Config extends ConfigurationOption
{
protected int $batchSize = 100;
protected ?string $googleCloudProject = null;
protected ?string $googleApplicationCredential = null;
protected bool $allowEnvCredentialOverride = false;
protected string $collection;
protected string $collectionName = 'phpfastcache';

/**
* @see \Google\Cloud\Firestore\FirestoreClient::DEFAULT_DATABASE
*/
protected string $databaseName = '(default)';

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

public function getBatchSize(): int
{
return $this->batchSize;
}

public function setBatchSize(int $batchSize): Config
{
return $this->setProperty('batchSize', $batchSize);
}

/**
* @return string
* @deprecated As of 9.2, will be removed in v10.
* @see self::getCollectionName()
*/
public function getCollection(): string
{
return $this->collection;
return $this->collectionName;
}

/**
* @param string $collectionName
* @return Config
* @throws PhpfastcacheLogicException
* @see self::setCollectionName()
* @deprecated As of 9.2, will be removed in v10.
*/
public function setCollection(string $collectionName): Config
{
if (isset($this->collectionName) && $collectionName !== $this->collectionName) {
trigger_error('getCollection/setCollection methods are deprecated, use getCollectionName/setCollectionName instead', E_USER_DEPRECATED);
}
return $this->setProperty('collectionName', $collectionName);
}

/**
* @return string
*/
public function getCollectionName(): string
{
return $this->collectionName;
}

/**
* @param string $collection
* @param string $collectionName
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setCollection(string $collection): Config
public function setCollectionName(string $collectionName): Config
{
return $this->setProperty('collectionName', $collectionName);
}

/**
* @return string
*/
public function getDatabaseName(): string
{
return $this->setProperty('collection', $collection);
return $this->databaseName;
}

/**
* @param string $databaseName
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setDatabaseName(string $databaseName): Config
{
return $this->setProperty('databaseName', $databaseName);
}



/**
* @return string|null
*/
Expand Down
Loading

0 comments on commit 5f3cae8

Please sign in to comment.