From d4702b8d6a64a48cfab7259248ecbecf3b6135e2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 31 Jul 2023 23:01:27 +0800 Subject: [PATCH] [9.x] Normalise predis command argument where it maybe an object. (#47902) * [9.x] Normalise predis command argument where it maybe an object. Starting from predis 2.1.1 it is possible to apply an implementation of `Predis\Command\Argument\ArrayableArgument` fixes laravel/telescope#1366 Signed-off-by: Mior Muhammad Zaki * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * formatting --------- Signed-off-by: Mior Muhammad Zaki Co-authored-by: StyleCI Bot Co-authored-by: Taylor Otwell --- Connections/Connection.php | 15 ++++++++++++++- Connections/PredisConnection.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Connections/Connection.php b/Connections/Connection.php index e3e55e9..69ed5c1 100644 --- a/Connections/Connection.php +++ b/Connections/Connection.php @@ -118,12 +118,25 @@ public function command($method, array $parameters = []) $time = round((microtime(true) - $start) * 1000, 2); if (isset($this->events)) { - $this->event(new CommandExecuted($method, $parameters, $time, $this)); + $this->event(new CommandExecuted( + $method, $this->parseParametersForEvent($parameters), $time, $this + )); } return $result; } + /** + * Parse the command's parameters for event dispatching. + * + * @param array $parameters + * @return array + */ + protected function parseParametersForEvent(array $parameters) + { + return $parameters; + } + /** * Fire the given event if possible. * diff --git a/Connections/PredisConnection.php b/Connections/PredisConnection.php index f642dd6..94f7cb4 100644 --- a/Connections/PredisConnection.php +++ b/Connections/PredisConnection.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Contracts\Redis\Connection as ConnectionContract; +use Predis\Command\Argument\ArrayableArgument; /** * @mixin \Predis\Client @@ -50,4 +51,20 @@ public function createSubscription($channels, Closure $callback, $method = 'subs unset($loop); } + + /** + * Parse the command's parameters for event dispatching. + * + * @param array $parameters + * @return array + */ + protected function parseParametersForEvent(array $parameters) + { + return collect($parameters) + ->transform(function ($parameter) { + return $parameter instanceof ArrayableArgument + ? $parameter->toArray() + : $parameter; + })->all(); + } }