Skip to content

Commit

Permalink
fix: handle response parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
adamczykpiotr committed Dec 9, 2023
1 parent b3b04aa commit 008bad5
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/Telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Telescope
/**
* The list of hidden request headers.
*
* @var array<int|string, string|callable>
* @var array<int|string, string|Closure>
*/
public static $hiddenRequestHeaders = [
'authorization',
Expand All @@ -85,7 +85,7 @@ class Telescope
/**
* The list of hidden request parameters.
*
* @var array<int|string, string|callable>
* @var array<int|string, string|Closure>
*/
public static $hiddenRequestParameters = [
'password',
Expand All @@ -95,7 +95,7 @@ class Telescope
/**
* The list of hidden response parameters.
*
* @var array<int|string, string|callable>
* @var array<int|string, string|Closure>
*/
public static $hiddenResponseParameters = [];

Expand Down Expand Up @@ -729,10 +729,18 @@ protected static function collectUpdates($batchId)
*/
public static function hideRequestHeaders(array $headers)
{
static::$hiddenRequestHeaders = array_values(array_unique(array_merge(
static::$hiddenRequestHeaders,
$headers
)));
/**
* @var Collection<int, string> $regular
* @var Collection<string, Closure> $closures
*/
[$closures, $regular] = Collection::wrap($headers)
->merge(static::$hiddenRequestHeaders)
->partition(fn($item) => $item instanceof Closure);

static::$hiddenRequestHeaders = $regular
->unique()
->merge($closures)
->toArray();

return new static;
}
Expand Down Expand Up @@ -761,10 +769,18 @@ public static function hideRequestParameters(array $attributes)
*/
public static function hideResponseParameters(array $attributes)
{
static::$hiddenResponseParameters = array_values(array_unique(array_merge(
static::$hiddenResponseParameters,
$attributes
)));
/**
* @var Collection<int, string> $regular
* @var Collection<string, Closure> $closures
*/
[$closures, $regular] = Collection::wrap($attributes)
->merge(static::$hiddenResponseParameters)
->partition(fn($item) => $item instanceof Closure);

static::$hiddenResponseParameters = $regular
->unique()
->merge($closures)
->toArray();

return new static;
}
Expand Down

0 comments on commit 008bad5

Please sign in to comment.