Skip to content

Commit

Permalink
Merge pull request #738 from dkulyk/added_ignored_events
Browse files Browse the repository at this point in the history
Added support for event ignoring.
  • Loading branch information
taylorotwell authored Sep 18, 2019
2 parents 48124f7 + f895fff commit f856809
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
7 changes: 6 additions & 1 deletion config/telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@
],

Watchers\DumpWatcher::class => env('TELESCOPE_DUMP_WATCHER', true),
Watchers\EventWatcher::class => env('TELESCOPE_EVENT_WATCHER', true),

Watchers\EventWatcher::class => [
'enabled' => env('TELESCOPE_EVENT_WATCHER', true),
'ignore' => [],
],

Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true),
Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true),
Watchers\LogWatcher::class => env('TELESCOPE_LOG_WATCHER', true),
Expand Down
15 changes: 13 additions & 2 deletions src/Watchers/EventWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ protected function formatClosureListener(Closure $listener)
*/
protected function shouldIgnore($eventName)
{
return Telescope::$ignoreFrameworkEvents &&
$this->eventIsFiredByTheFramework($eventName);
return $this->eventIsIgnored($eventName) ||
(Telescope::$ignoreFrameworkEvents && $this->eventIsFiredByTheFramework($eventName));
}

/**
Expand All @@ -149,4 +149,15 @@ protected function eventIsFiredByTheFramework($eventName)
$eventName
);
}

/**
* Determine if the event is ignored manually.
*
* @param string $eventName
* @return bool
*/
protected function eventIsIgnored($eventName)
{
return Str::is($this->options['ignore'] ?? [], $eventName);
}
}
24 changes: 23 additions & 1 deletion tests/Watchers/EventWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ protected function getEnvironmentSetUp($app)
parent::getEnvironmentSetUp($app);

$app->get('config')->set('telescope.watchers', [
EventWatcher::class => true,
EventWatcher::class => [
'enabled' => true,
'ignore' => [
IgnoredEvent::class,
],
],
]);
}

Expand Down Expand Up @@ -49,6 +54,15 @@ public function test_event_watcher_stores_payloads()
$this->assertContains('Laravel', $entry->content['payload']['data']);
$this->assertContains('PHP', $entry->content['payload']['data']);
}

public function test_event_watcher_ignore_event()
{
event(new IgnoredEvent());

$entry = $this->loadTelescopeEntries()->first();

$this->assertNull($entry);
}
}

class DummyEvent
Expand All @@ -65,3 +79,11 @@ public function handle()
//
}
}

class IgnoredEvent
{
public function handle()
{
//
}
}

0 comments on commit f856809

Please sign in to comment.