Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separator payload #599

Merged
merged 2 commits into from
Nov 24, 2021
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
15 changes: 13 additions & 2 deletions docs/usage/framework-agnostic-php-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ ray(['John', 'Paul', 'George', 'Ringo'])->label('Beatles');

![screenshot](/docs/ray/v1/images/label.png)

### Showing a separator

Another way to visually separate items in Ray, is to call `seperator`.

```php
ray('first item');

ray()->separator();

ray('second item');
```

![screenshot](/docs/ray/v1/images/separator.png)


### Creating a new screen
Expand Down Expand Up @@ -193,7 +206,6 @@ foreach (range(1, 10) as $i) {

If the argument passed to `limit()` is a negative number or zero, limiting is disabled.


### Using a rate limiter

A rate limiter can help to reduce the amount of sent messages. This would avoid spamming the desktop app, which can be helpful when using Ray in loops.
Expand All @@ -213,7 +225,6 @@ Ray::rateLimiter()->clear();

A message to the desktop app will be sent once to notify the user the rate limit has been reached.


### Sending a payload once

To only send a payload once, use the `once` function. This is useful for debugging loops.
Expand Down
1 change: 1 addition & 0 deletions docs/usage/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ To display something in Ray use the `ray()` function. It accepts everything: str
| `ray()->rateLimiter()->clear()` | Clears the rate limits |
| `ray()->raw($value)` | Send raw output of a value to Ray without fancy formatting |
| `ray(…)->red()` | Output in red |
| `ray()->separator()` | Add a visual separator |
| `ray()->showApp()` | Bring the app to the foreground |
| `ray(…)->small()` | Output text smaller |
| `ray()->table($array, $label)` | Format an associative array with optional label |
Expand Down
11 changes: 11 additions & 0 deletions src/Payloads/SeparatorPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Spatie\Ray\Payloads;

class SeparatorPayload extends Payload
{
public function getType(): string
{
return 'separator';
}
}
8 changes: 8 additions & 0 deletions src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Spatie\Ray\Payloads\NotifyPayload;
use Spatie\Ray\Payloads\PhpInfoPayload;
use Spatie\Ray\Payloads\RemovePayload;
use Spatie\Ray\Payloads\SeparatorPayload;
use Spatie\Ray\Payloads\ShowAppPayload;
use Spatie\Ray\Payloads\SizePayload;
use Spatie\Ray\Payloads\TablePayload;
Expand Down Expand Up @@ -497,6 +498,13 @@ public function pause(): self
return $this;
}

public function separator(): self
{
$payload = new SeparatorPayload();

return $this->sendRequest($payload);
}

public function html(string $html = ''): self
{
$payload = new HtmlPayload($html);
Expand Down
8 changes: 8 additions & 0 deletions tests/RayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,14 @@ public function it_can_dump_a_string_with_a_global_function_name()
$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_can_send_a_separator()
{
$this->ray->send('separator');

$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

protected function getNewRay(): Ray
{
return Ray::create($this->client, 'fakeUuid');
Expand Down
21 changes: 21 additions & 0 deletions tests/__snapshots__/RayTest__it_can_send_a_separator__1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"uuid": "fakeUuid",
"payloads": [
{
"type": "log",
"content": {
"values": [
"separator"
]
},
"origin": {
"file": "\/tests\/RayTest.php",
"line_number": "xxx",
"hostname": "fake-hostname"
}
}
],
"meta": []
}
]