Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/Stackify/Log/Entities/Api/WebRequestDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Stackify\Log\Entities\Api;

use Stackify\Utils\TypeConverter;

class WebRequestDetail
{

Expand Down Expand Up @@ -125,7 +127,7 @@ public static function getRequestMap($data, $maskValues = false)
foreach ($data as $key => $value) {
$result[$key] = $maskValues
? self::HIDDEN_VALUE
: self::stringify($value);
: TypeConverter::stringify($value);
}
}
return empty($result) ? null : $result;
Expand Down Expand Up @@ -193,25 +195,4 @@ private function getHeaders()
return empty($headers) ? null : $headers;
}

/**
* Converts any PHP type to string
* @param mixed $value
* @return string
*/
private static function stringify($value)
{
$string = '';
if (is_scalar($value)) {
// integer, float, string, boolean
$string = (string)$value;
} elseif (is_resource($value)) {
// resource
$string = '[resource]';
} else {
// array, object, null, callable
$string = json_encode($value);
}
return $string;
}

}
29 changes: 29 additions & 0 deletions src/Stackify/Utils/TypeConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Stackify\Utils;

class TypeConverter
{

/**
* Converts any PHP type to string
* @param mixed $value
* @return string
*/
public static function stringify($value)
{
$string = '';
if (is_scalar($value)) {
// integer, float, string, boolean
$string = (string)$value;
} elseif (is_resource($value)) {
// resource
$string = '[resource]';
} else {
// array, object, null, callable
$string = json_encode($value);
}
return $string;
}

}