snappymail/plugins/cache-redis/Predis/Connection/CompositeStreamConnection.php
google-labs-jules[bot] 2548ed59da Fix PHP 8.4 implicit nullable parameter deprecations in Predis library
PHP 8.4 deprecates implicitly nullable parameter types. Parameters with a default value of `null` must now be explicitly marked as nullable (e.g., `?Type $var = null`).

This change updates the vendored `Predis` library in `plugins/cache-redis/` to comply with this requirement. It scans for function signatures like `Type $var = null` and updates them to `?Type $var = null`. This ensures compatibility with PHP 8.4 and PHP 8.5 while maintaining backward compatibility.

Affected files include `Predis` interfaces, connection classes, and command definitions.
Also updated PHPDoc `@method` annotations to reflect nullable types.
2026-01-16 15:11:52 +00:00

125 lines
2.9 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Connection;
use InvalidArgumentException;
use Predis\Command\CommandInterface;
use Predis\Protocol\ProtocolProcessorInterface;
use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor;
/**
* Connection abstraction to Redis servers based on PHP's stream that uses an
* external protocol processor defining the protocol used for the communication.
*/
class CompositeStreamConnection extends StreamConnection implements CompositeConnectionInterface
{
protected $protocol;
/**
* @param ParametersInterface $parameters Initialization parameters for the connection.
* @param ProtocolProcessorInterface $protocol Protocol processor.
*/
public function __construct(
ParametersInterface $parameters,
?ProtocolProcessorInterface $protocol = null
) {
$this->parameters = $this->assertParameters($parameters);
$this->protocol = $protocol ?: new TextProtocolProcessor();
}
/**
* {@inheritdoc}
*/
public function getProtocol()
{
return $this->protocol;
}
/**
* {@inheritdoc}
*/
public function writeBuffer($buffer)
{
$this->write($buffer);
}
/**
* {@inheritdoc}
*/
public function readBuffer($length)
{
if ($length <= 0) {
throw new InvalidArgumentException('Length parameter must be greater than 0.');
}
$value = '';
$socket = $this->getResource();
do {
$chunk = fread($socket, $length);
if ($chunk === false || $chunk === '') {
$this->onConnectionError('Error while reading bytes from the server.');
}
$value .= $chunk;
} while (($length -= strlen($chunk)) > 0);
return $value;
}
/**
* {@inheritdoc}
*/
public function readLine()
{
$value = '';
$socket = $this->getResource();
do {
$chunk = fgets($socket);
if ($chunk === false || $chunk === '') {
$this->onConnectionError('Error while reading line from the server.');
}
$value .= $chunk;
} while (substr($value, -2) !== "\r\n");
return substr($value, 0, -2);
}
/**
* {@inheritdoc}
*/
public function writeRequest(CommandInterface $command)
{
$this->protocol->write($this, $command);
}
/**
* {@inheritdoc}
*/
public function read()
{
return $this->protocol->read($this);
}
/**
* {@inheritdoc}
*/
public function __sleep()
{
return array_merge(parent::__sleep(), ['protocol']);
}
}