| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/apache/htdocs/app/vendor/laravel/telescope/src/ |
Upload File : |
<?php
namespace Laravel\Telescope;
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Laravel\Octane\Events\RequestReceived;
use Laravel\Octane\Events\RequestTerminated;
use Laravel\Telescope\Contracts\EntriesRepository;
trait ListensForStorageOpportunities
{
/**
* An array indicating how many jobs are processing.
*
* @var array
*/
protected static $processingJobs = [];
/**
* Register listeners that store the recorded Telescope entries.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public static function listenForStorageOpportunities($app)
{
static::manageRecordingStateForOctane($app);
static::storeEntriesBeforeTermination($app);
static::storeEntriesAfterWorkerLoop($app);
}
/**
* Manage starting and stopping the recording state for Octane.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected static function manageRecordingStateForOctane($app)
{
$app['events']->listen(RequestReceived::class, function ($event) {
if (static::requestIsToApprovedUri($event->request)) {
static::startRecording();
}
});
$app['events']->listen(RequestTerminated::class, function ($event) {
static::stopRecording();
});
}
/**
* Store the entries in queue before the application termination.
*
* This handles storing entries for HTTP requests and Artisan commands.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected static function storeEntriesBeforeTermination($app)
{
$app->terminating(function () use ($app) {
static::store($app[EntriesRepository::class]);
});
}
/**
* Store entries after the queue worker loops.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected static function storeEntriesAfterWorkerLoop($app)
{
$app['events']->listen(JobProcessing::class, function ($event) {
if ($event->connectionName !== 'sync') {
static::startRecording();
static::$processingJobs[] = true;
}
});
$app['events']->listen(JobProcessed::class, function ($event) use ($app) {
static::storeIfDoneProcessingJob($event, $app);
});
$app['events']->listen(JobFailed::class, function ($event) use ($app) {
static::storeIfDoneProcessingJob($event, $app);
});
$app['events']->listen(JobExceptionOccurred::class, function () {
array_pop(static::$processingJobs);
});
}
/**
* Store the recorded entries if totally done processing the current job.
*
* @param \Illuminate\Queue\Events\JobProcessed $event
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected static function storeIfDoneProcessingJob($event, $app)
{
array_pop(static::$processingJobs);
if (empty(static::$processingJobs) && $event->connectionName !== 'sync') {
static::store($app[EntriesRepository::class]);
static::stopRecording();
}
}
}