-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context allows you to track current and historic "context" (information about the world) throughout a single request / command and across logical boundaries, such as queued jobs.
- Loading branch information
1 parent
5e87357
commit abfd659
Showing
12 changed files
with
1,163 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Illuminate\Log\Context; | ||
|
||
use Illuminate\Queue\Events\JobProcessing; | ||
use Illuminate\Queue\Queue; | ||
use Illuminate\Support\Facades\Context; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ContextServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->scoped(Repository::class); | ||
} | ||
|
||
/** | ||
* Boot the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
Queue::createPayloadUsing(function ($connection, $queue, $payload) { | ||
$context = Context::dehydrate(); | ||
|
||
return $context === null ? $payload : [ | ||
...$payload, | ||
'illuminate:log:context' => $context, | ||
]; | ||
}); | ||
|
||
$this->app['events']->listen(function (JobProcessing $event) { | ||
Context::hydrate($event->job->payload()['illuminate:log:context'] ?? null); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Illuminate\Log\Context\Events; | ||
|
||
class ContextDehydrating | ||
{ | ||
/** | ||
* The context instance. | ||
* | ||
* @var \Illuminate\Log\Context\Repository | ||
*/ | ||
public $context; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param \Illuminate\Log\Context\Repository $context | ||
*/ | ||
public function __construct($context) | ||
{ | ||
$this->context = $context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Illuminate\Log\Context\Events; | ||
|
||
class ContextHydrated | ||
{ | ||
/** | ||
* The context instance. | ||
* | ||
* @var \Illuminate\Log\Context\Repository | ||
*/ | ||
public $context; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param \Illuminate\Log\Context\Repository $context | ||
*/ | ||
public function __construct($context) | ||
{ | ||
$this->context = $context; | ||
} | ||
} |
Oops, something went wrong.