Predis to v2.2.2

This commit is contained in:
the-djmaze 2024-04-02 20:15:23 +02:00
parent f6b440adef
commit 84ffe1e552
259 changed files with 2407 additions and 9937 deletions

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (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.
@ -11,11 +12,11 @@
namespace Predis\PubSub;
use InvalidArgumentException;
/**
* Method-dispatcher loop built around the client-side abstraction of a Redis
* PUB / SUB context.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class DispatcherLoop
{
@ -30,7 +31,7 @@ class DispatcherLoop
*/
public function __construct(Consumer $pubsub)
{
$this->callbacks = array();
$this->callbacks = [];
$this->pubsub = $pubsub;
}
@ -39,12 +40,12 @@ class DispatcherLoop
*
* @param mixed $callable A callback.
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function assertCallback($callable)
{
if (!is_callable($callable)) {
throw new \InvalidArgumentException('The given argument must be a callable object.');
throw new InvalidArgumentException('The given argument must be a callable object.');
}
}
@ -91,11 +92,11 @@ class DispatcherLoop
* Binds a callback to a channel.
*
* @param string $channel Channel name.
* @param Callable $callback A callback.
* @param callable $callback A callback.
*/
public function attachCallback($channel, $callback)
{
$callbackName = $this->getPrefixKeys().$channel;
$callbackName = $this->getPrefixKeys() . $channel;
$this->assertCallback($callback);
$this->callbacks[$callbackName] = $callback;
@ -109,7 +110,7 @@ class DispatcherLoop
*/
public function detachCallback($channel)
{
$callbackName = $this->getPrefixKeys().$channel;
$callbackName = $this->getPrefixKeys() . $channel;
if (isset($this->callbacks[$callbackName])) {
unset($this->callbacks[$callbackName]);
@ -128,7 +129,7 @@ class DispatcherLoop
if ($kind !== Consumer::MESSAGE && $kind !== Consumer::PMESSAGE) {
if (isset($this->subscriptionCallback)) {
$callback = $this->subscriptionCallback;
call_user_func($callback, $message);
call_user_func($callback, $message, $this);
}
continue;
@ -136,10 +137,10 @@ class DispatcherLoop
if (isset($this->callbacks[$message->channel])) {
$callback = $this->callbacks[$message->channel];
call_user_func($callback, $message->payload);
call_user_func($callback, $message->payload, $this);
} elseif (isset($this->defaultCallback)) {
$callback = $this->defaultCallback;
call_user_func($callback, $message);
call_user_func($callback, $message, $this);
}
}
}