Skip to content

[Cache] Add Union Types #41587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface AdapterInterface extends CacheItemPoolInterface
*
* @return CacheItem
*/
public function getItem($key);
public function getItem(mixed $key);

/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
return apcu_exists($id);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function delete(string $key): bool
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
if ($this->maxItems) {
Expand All @@ -120,7 +120,7 @@ public function hasItem($key)
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
if (!$isHit = $this->hasItem($key)) {
$value = null;
Expand Down Expand Up @@ -151,7 +151,7 @@ public function getItems(array $keys = [])
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
\assert('' !== CacheItem::validateKey($key));
unset($this->values[$key], $this->expiries[$key]);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
$syncItem = self::$syncItem;
$misses = [];
Expand Down Expand Up @@ -186,7 +186,7 @@ private function generateItems(iterable $items, int $adapterIndex)
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
foreach ($this->adapters as $adapter) {
if ($adapter->hasItem($key)) {
Expand Down Expand Up @@ -223,7 +223,7 @@ public function clear(string $prefix = '')
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
$deleted = true;
$i = $this->adapterCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function __construct(\CouchbaseBucket $bucket, string $namespace = '', in
$this->marshaller = $marshaller ?? new DefaultMarshaller();
}

/**
* @param array|string $servers
*/
public static function createConnection($servers, array $options = []): \CouchbaseBucket
public static function createConnection(array | string $servers, array $options = []): \CouchbaseBucket
{
if (\is_string($servers)) {
$servers = [$servers];
Expand Down Expand Up @@ -182,15 +179,15 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave($id): bool
protected function doHave(mixed $id): bool
{
return false !== $this->bucket->get($id);
}

/**
* {@inheritdoc}
*/
protected function doClear($namespace): bool
protected function doClear(string $namespace): bool
{
if ('' === $namespace) {
$this->bucket->manager()->flush();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
return $this->provider->contains($id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function isSupported()
*
* @throws \ErrorException When invalid options or servers are provided
*/
public static function createConnection($servers, array $options = [])
public static function createConnection(array | string $servers, array $options = [])
{
if (\is_string($servers)) {
$servers = [$servers];
Expand Down Expand Up @@ -285,7 +285,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Cache/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
return (self::$createCacheItem)($key);
}
Expand All @@ -68,7 +68,7 @@ public function getItems(array $keys = [])
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
return false;
}
Expand All @@ -88,7 +88,7 @@ public function clear(string $prefix = '')
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
return true;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function commit()
/**
* {@inheritdoc}
*/
public function delete(string $key): bool
public function delete(mixed $key): bool
{
return $this->deleteItem($key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
* @throws InvalidArgumentException When namespace contains invalid characters
*/
public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
public function __construct(\PDO | Connection | string $connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
{
if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
Expand Down Expand Up @@ -259,7 +259,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
$stmt = $this->getConnection()->prepare($sql);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
Expand Down Expand Up @@ -167,7 +167,7 @@ public function getItems(array $keys = [])
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
Expand All @@ -184,7 +184,7 @@ public function hasItem($key)
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
if (!\is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
if ($this->appendOnly && isset($this->values[$id])) {
return true;
Expand Down Expand Up @@ -292,7 +292,7 @@ protected function doDelete(array $ids)
return $this->doCommonDelete($ids);
}

protected function doUnlink($file)
protected function doUnlink(string $file)
{
unset(self::$valuesCache[$file]);

Expand Down Expand Up @@ -323,7 +323,7 @@ class LazyValue
{
public $file;

public function __construct($file)
public function __construct(string $file)
{
$this->file = $file;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
$item = $this->pool->getItem($this->getId($key));

Expand All @@ -146,7 +146,7 @@ public function getItems(array $keys = [])
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
return $this->pool->hasItem($this->getId($key));
}
Expand All @@ -170,7 +170,7 @@ public function clear(string $prefix = '')
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
return $this->pool->deleteItem($this->getId($key));
}
Expand Down Expand Up @@ -259,7 +259,7 @@ private function generateItems(iterable $items)
}
}

private function getId($key): string
private function getId(mixed $key): string
{
\assert('' !== CacheItem::validateKey($key));

Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Component/Cache/Adapter/Psr16Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
*/
class Psr16Adapter extends AbstractAdapter implements PruneableInterface, ResettableInterface
{
use ProxyTrait;
/**
* @internal
*/
protected const NS_SEPARATOR = '_';

use ProxyTrait;

private $miss;

public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0)
Expand All @@ -55,7 +54,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(mixed $id)
{
return $this->pool->has($id);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Symfony/Component/Cache/Adapter/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
namespace Symfony\Component\Cache\Adapter;

use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\Traits\RedisProxy;
use Symfony\Component\Cache\Traits\RedisTrait;

class RedisAdapter extends AbstractAdapter
{
use RedisTrait;

/**
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
* @param string $namespace The default namespace
* @param int $defaultLifetime The default lifetime
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy $redisClient The redis client
* @param string $namespace The default namespace
* @param int $defaultLifetime The default lifetime
*/
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
public function __construct(mixed $redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
* @param string $namespace The default namespace
* @param int $defaultLifetime The default lifetime
*/
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
public function __construct(mixed $redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redisClient->getConnection())));
Expand Down Expand Up @@ -256,7 +256,7 @@ protected function doInvalidate(array $tagIds): bool
*
* @return array Filtered list of the valid moved keys (only those that existed)
*/
private function renameKeys($redis, array $ids): array
private function renameKeys(mixed $redis, array $ids): array
{
$newIds = [];
$uniqueToken = bin2hex(random_bytes(10));
Expand Down
9 changes: 4 additions & 5 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
*/
class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface, LoggerAwareInterface
{
public const TAGS_PREFIX = "\0tags\0";

use ContractsTrait;
use LoggerAwareTrait;
use ProxyTrait;
public const TAGS_PREFIX = "\0tags\0";

private $deferred = [];
private $tags;
Expand Down Expand Up @@ -155,7 +154,7 @@ public function invalidateTags(array $tags)
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key)
{
if ($this->deferred) {
$this->commit();
Expand Down Expand Up @@ -186,7 +185,7 @@ public function hasItem($key)
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key)
{
foreach ($this->getItems([$key]) as $item) {
return $item;
Expand Down Expand Up @@ -252,7 +251,7 @@ public function clear(string $prefix = '')
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key)
{
return $this->deleteItems([$key]);
}
Expand Down
Loading