Skip to content
Open
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
58 changes: 58 additions & 0 deletions Clockwork/DataSource/LaravelScoutDataSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php namespace Clockwork\DataSource;

use Clockwork\Request\Request;
use Clockwork\Request\Timeline\Timeline;

use Illuminate\Contracts\Events\Dispatcher;

// Data source for Laravel Scout component, provides searches
class LaravelScoutDataSource extends DataSource
{
// Event dispatcher
protected $dispatcher;

// Timeline data structure for collected searches
protected $searches;

// Create a new data source instance, takes an event dispatcher as argument
public function __construct(Dispatcher $dispatcher)
{
$this->dispatcher = $dispatcher;

$this->searches = new Timeline;
}

// Adds rendered searches to the request
public function resolve(Request $request)
{
//$request->searchesData = array_merge($request->searchesData, $this->searches->finalize());

return $request;
}

// Reset the data source to an empty state, clearing any collected data
public function reset()
{
$this->searches = new Timeline;
}

// Listen to the search events
public function listenToEvents()
{
$this->dispatcher->listen(\Laravel\Scout\Events\ModelsFlushed::class, function ($event) {
$this->searches->event('Flush models from search', [
'name' => 'model ' . get_class($event->models[0]),
'start' => $time = microtime(true),
'end' => $time,
]);
});

$this->dispatcher->listen(\Laravel\Scout\Events\ModelsImported::class, function ($event) {
$this->searches->event('Import models into search', [
'name' => 'model ' . get_class($event->models[0]),
'start' => $time = microtime(true),
'end' => $time,
]);
});
}
}
23 changes: 18 additions & 5 deletions Clockwork/Support/Laravel/ClockworkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

use Clockwork\Clockwork;
use Clockwork\Authentication\AuthenticatorInterface;
use Clockwork\DataSource\{
EloquentDataSource, LaravelCacheDataSource, LaravelDataSource, LaravelEventsDataSource, LaravelHttpClientDataSource,
LaravelNotificationsDataSource, LaravelQueueDataSource, LaravelRedisDataSource, LaravelViewsDataSource, SwiftDataSource,
TwigDataSource, XdebugDataSource
};
use Clockwork\DataSource\{EloquentDataSource,
LaravelCacheDataSource,
LaravelDataSource,
LaravelEventsDataSource,
LaravelHttpClientDataSource,
LaravelNotificationsDataSource,
LaravelQueueDataSource,
LaravelRedisDataSource,
LaravelScoutDataSource,
LaravelViewsDataSource,
SwiftDataSource,
TwigDataSource,
XdebugDataSource};
use Clockwork\Helpers\StackFilter;
use Clockwork\Request\Request;
use Clockwork\Storage\StorageInterface;
Expand Down Expand Up @@ -194,6 +202,10 @@ protected function registerDataSources()
return $dataSource;
});

$this->app->singleton('clockwork.scout', function ($app) {
return (new LaravelScoutDataSource($app['events']));
});

$this->app->singleton('clockwork.swift', function ($app) {
return new SwiftDataSource($app['mailer']->getSwiftMailer());
});
Expand Down Expand Up @@ -230,6 +242,7 @@ protected function registerAliases()
$this->app->alias('clockwork.notifications', LaravelNotificationsDataSource::class);
$this->app->alias('clockwork.queue', LaravelQueueDataSource::class);
$this->app->alias('clockwork.redis', LaravelRedisDataSource::class);
$this->app->alias('clockwork.scout', LaravelScoutDataSource::class);
$this->app->alias('clockwork.swift', SwiftDataSource::class);
$this->app->alias('clockwork.xdebug', XdebugDataSource::class);
}
Expand Down
2 changes: 2 additions & 0 deletions Clockwork/Support/Laravel/ClockworkSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function addDataSources()
if ($this->isFeatureEnabled('database')) $clockwork->addDataSource($this->app['clockwork.eloquent']);
if ($this->isFeatureEnabled('cache')) $clockwork->addDataSource($this->app['clockwork.cache']);
if ($this->isFeatureEnabled('redis')) $clockwork->addDataSource($this->app['clockwork.redis']);
if ($this->isFeatureEnabled('scout')) $clockwork->addDataSource($this->app['clockwork.scout']);
if ($this->isFeatureEnabled('queue')) $clockwork->addDataSource($this->app['clockwork.queue']);
if ($this->isFeatureEnabled('events')) $clockwork->addDataSource($this->app['clockwork.events']);
if ($this->isFeatureEnabled('notifications')) {
Expand Down Expand Up @@ -170,6 +171,7 @@ public function listenToEvents()
if ($this->isFeatureEnabled('cache')) $this->app['clockwork.cache']->listenToEvents();
if ($this->isFeatureEnabled('database')) $this->app['clockwork.eloquent']->listenToEvents();
if ($this->isFeatureEnabled('events')) $this->app['clockwork.events']->listenToEvents();
if ($this->isFeatureEnabled('scout')) $this->app['clockwork.scout']->listenToEvents();
if ($this->isFeatureEnabled('http_requests')) $this->app['clockwork.http-requests']->listenToEvents();
if ($this->isFeatureEnabled('notifications')) {
$this->isFeatureAvailable('notifications-events')
Expand Down
5 changes: 5 additions & 0 deletions Clockwork/Support/Laravel/config/clockwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
'enabled' => env('CLOCKWORK_REDIS_ENABLED', true)
],

// Scout searches
'scout' => [
'enabled' => env('CLOCKWORK_SCOUT_ENABLED', true)
],

// Routes list
'routes' => [
'enabled' => env('CLOCKWORK_ROUTES_ENABLED', false),
Expand Down