Skip to content

Commit

Permalink
Merge pull request #829 from spatie/feature/clipboard
Browse files Browse the repository at this point in the history
Feature/clipboard
  • Loading branch information
timvandijck authored Sep 1, 2023
2 parents 66d011b + 53e9742 commit ef76965
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/PayloadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ protected function getPayload($value): Payload

$primitiveValue = ArgumentConverter::convertToPrimitive($value);

return new LogPayload($primitiveValue);
return new LogPayload($primitiveValue, $value);
}
}
26 changes: 25 additions & 1 deletion src/Payloads/LogPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

namespace Spatie\Ray\Payloads;

use Exception;
use Spatie\Ray\ArgumentConverter;

class LogPayload extends Payload
{
/** @var array */
protected $values;

/** @var array */
protected $meta = [];

public static function createForArguments(array $arguments): Payload
{
$dumpedArguments = array_map(function ($argument) {
Expand All @@ -18,7 +22,7 @@ public static function createForArguments(array $arguments): Payload
return new static($dumpedArguments);
}

public function __construct($values)
public function __construct($values, $rawValues = [])
{
if (! is_array($values)) {
if (is_int($values) && $values >= 11111111111111111) {
Expand All @@ -28,6 +32,12 @@ public function __construct($values)
$values = [$values];
}

$this->meta = [
[
'clipboard_data' => $this->getClipboardData($rawValues),
],
];

$this->values = $values;
}

Expand All @@ -40,6 +50,20 @@ public function getContent(): array
{
return [
'values' => $this->values,
'meta' => $this->meta,
];
}

protected function getClipboardData($value): string
{
if (is_string($value) || is_numeric($value)) {
return (string) $value;
}

try {
return var_export($value, true);
} catch (Exception $ex) {
return '';
}
}
}

0 comments on commit ef76965

Please sign in to comment.