/
LaravelRequestFetcher.php
34 lines (27 loc) · 1.03 KB
/
LaravelRequestFetcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Sentry\Laravel\Http;
use Illuminate\Container\Container;
use Psr\Http\Message\ServerRequestInterface;
use Sentry\Integration\RequestFetcher;
use Sentry\Integration\RequestFetcherInterface;
class LaravelRequestFetcher implements RequestFetcherInterface
{
/**
* They key in the container where a PSR-7 instance of the current request could be stored.
*/
public const CONTAINER_PSR7_INSTANCE_KEY = 'sentry-laravel.psr7.request';
public function fetchRequest(): ?ServerRequestInterface
{
$container = Container::getInstance();
// If there is no request bound to the container
// we are not dealing with a HTTP request and there
// is no request to fetch for us so we can exit early.
if (!$container->bound('request')) {
return null;
}
if ($container->bound(self::CONTAINER_PSR7_INSTANCE_KEY)) {
return $container->make(self::CONTAINER_PSR7_INSTANCE_KEY);
}
return (new RequestFetcher)->fetchRequest();
}
}