Skip to content

Commit

Permalink
[9.x] Normalise predis command argument where it maybe an object. (#4…
Browse files Browse the repository at this point in the history
…7902)

* [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 <[email protected]>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* formatting

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent 856adc6 commit d4702b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions Connections/PredisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Contracts\Redis\Connection as ConnectionContract;
use Predis\Command\Argument\ArrayableArgument;

/**
* @mixin \Predis\Client
Expand Down Expand Up @@ -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();
}
}

0 comments on commit d4702b8

Please sign in to comment.