Skip to content

Commit a46454c

Browse files
committed
Telescope support.
1 parent 992b976 commit a46454c

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

config/laravel-developer.php renamed to config/developer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
'bearer' => 'testing',
2525
],
2626

27-
'interacts_telescope' => env('INTERACTS_TELESCOPE'),
27+
/**
28+
* If this is true, you should ensure you have telescope installed and the package will store exceptions in the telescope as well.
29+
*/
30+
'telescope' => env('DEV_TELESCOPE'),
2831
];

src/LaravelDeveloperServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function boot()
1212
{
1313
if ($this->app->runningInConsole()) {
1414
$this->publishes([
15-
__DIR__ . '/../config/laravel-developer.php' => config_path('developer.php'),
15+
__DIR__ . '/../config/developer.php' => config_path('developer.php'),
1616
], 'developer-config');
1717

1818
$migrationFileName = 'create_laravel_developer_table.php';
@@ -30,7 +30,7 @@ public function boot()
3030

3131
public function register()
3232
{
33-
$this->mergeConfigFrom(__DIR__ . '/../config/laravel-developer.php', 'developer');
33+
$this->mergeConfigFrom(__DIR__ . '/../config/developer.php', 'developer');
3434
$this->registerMacros();
3535
}
3636

src/Notifications/Slack.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Binarcode\LaravelDeveloper\Dtos\DevNotificationDto;
66
use Binarcode\LaravelDeveloper\Models\ExceptionLog;
7+
use Binarcode\LaravelDeveloper\Telescope\TelescopeDev;
78
use Binarcode\LaravelDeveloper\Telescope\TelescopeException;
89
use Illuminate\Support\Collection;
910
use Illuminate\Support\Facades\Notification as NotificationFacade;
@@ -20,6 +21,8 @@ class Slack
2021

2122
protected bool $persist = false;
2223

24+
protected bool $telescope = true;
25+
2326
public function __construct($args = null)
2427
{
2528
$this->queue = collect($args)->flatten();
@@ -59,8 +62,8 @@ private function send($item)
5962
tap(ExceptionLog::makeFromException($item), fn (ExceptionLog $log) => $log->save())
6063
);
6164

62-
if (config('developer.interacts_telescope')) {
63-
TelescopeException::recordException($item);
65+
if ($this->telescope && TelescopeDev::allow()) {
66+
TelescopeException::record($item);
6467
}
6568
} else {
6669
$dto = DevNotificationDto::makeFromException($item);
@@ -93,6 +96,13 @@ private function send($item)
9396
return $this;
9497
}
9598

99+
public function withoutTelescope(): self
100+
{
101+
$this->telescope = false;
102+
103+
return $this;
104+
}
105+
96106
public static function notifyUsing(?callable $notificator)
97107
{
98108
Slack::$notifyUsing = $notificator;

src/Telescope/TelescopeDev.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelDeveloper\Telescope;
4+
5+
class TelescopeDev
6+
{
7+
public static function allow(): bool
8+
{
9+
if (!class_exists('Laravel\\Telescope\\Telescope')) {
10+
logger('Telescope is not installed.');
11+
return false;
12+
}
13+
14+
return config('developer.telescope');
15+
}
16+
}

src/Telescope/TelescopeException.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
namespace Binarcode\LaravelDeveloper\Telescope;
44

5+
use Illuminate\Support\Arr;
6+
use Laravel\Telescope\ExceptionContext;
7+
use Laravel\Telescope\IncomingExceptionEntry;
8+
use Laravel\Telescope\Telescope;
59
use Throwable;
610

711
class TelescopeException
812
{
9-
public static function recordException(Throwable $exception, $message = null): void
13+
public static function record(Throwable $exception, $message = null): void
1014
{
11-
if (!class_exists('Laravel\\Telescope\\Telescope') ||
12-
!class_exists('Laravel\\Telescope\\IncomingExceptionEntry') ||
13-
!class_exists('Laravel\\Telescope\\ExceptionContext')
14-
) {
15-
return;
16-
}
17-
1815
$trace = collect($exception->getTrace())->map(function ($item) {
1916
return Arr::only($item, ['file', 'line']);
2017
})->toArray();
2118

22-
Telescope::recordException(
23-
IncomingExceptionEntry::make($exception, [
24-
'class' => get_class($exception),
25-
'file' => $exception->getFile(),
26-
'line' => $exception->getLine(),
27-
'message' => $message ?? $exception->getMessage(),
28-
'context' => null,
29-
'trace' => $trace,
30-
'line_preview' => ExceptionContext::get($exception),
31-
])
32-
);
19+
try {
20+
Telescope::recordException(
21+
IncomingExceptionEntry::make($exception, [
22+
'class' => get_class($exception),
23+
'file' => $exception->getFile(),
24+
'line' => $exception->getLine(),
25+
'message' => $message ?? $exception->getMessage(),
26+
'context' => null,
27+
'trace' => $trace,
28+
'line_preview' => ExceptionContext::get($exception),
29+
])
30+
);
31+
} catch (Throwable $e) {
32+
}
3333
}
3434
}

src/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function devLog(...$args): DevLog
6060
function telescopeException(Throwable $exception, $message = null): void
6161
{
6262
if (config('developer.interacts_telescope')) {
63-
TelescopeException::recordException($exception, $message);
63+
TelescopeException::record($exception, $message);
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)