3
3
namespace Sentry \Laravel \Tracing ;
4
4
5
5
use Closure ;
6
- use Illuminate \Contracts \Foundation \Application as LaravelApplication ;
7
6
use Illuminate \Http \Request ;
8
7
use Laravel \Lumen \Application as LumenApplication ;
9
8
use Sentry \SentrySdk ;
@@ -41,13 +40,6 @@ class Middleware
41
40
*/
42
41
private $ bootedTimestamp ;
43
42
44
- /**
45
- * The Laravel or Lumen application instance.
46
- *
47
- * @var LaravelApplication|LumenApplication
48
- */
49
- private $ app ;
50
-
51
43
/**
52
44
* Whether we should continue tracing after the response has been sent to the client.
53
45
*
@@ -71,27 +63,24 @@ class Middleware
71
63
72
64
/**
73
65
* Construct the Sentry tracing middleware.
74
- *
75
- * @param LaravelApplication|LumenApplication $app
76
66
*/
77
- public function __construct ($ app , bool $ continueAfterResponse = true )
67
+ public function __construct (bool $ continueAfterResponse = true )
78
68
{
79
- $ this ->app = $ app ;
80
69
$ this ->continueAfterResponse = $ continueAfterResponse ;
81
70
}
82
71
83
72
/**
84
73
* Handle an incoming request.
85
74
*
86
75
* @param \Illuminate\Http\Request $request
87
- * @param \Closure $next
76
+ * @param \Closure $next
88
77
*
89
78
* @return mixed
90
79
*/
91
80
public function handle (Request $ request , Closure $ next )
92
81
{
93
- if ($ this -> app ->bound (HubInterface::class)) {
94
- $ this ->startTransaction ($ request , $ this -> app -> make (HubInterface::class));
82
+ if (app () ->bound (HubInterface::class)) {
83
+ $ this ->startTransaction ($ request , app (HubInterface::class));
95
84
}
96
85
97
86
return $ next ($ request );
@@ -101,14 +90,14 @@ public function handle(Request $request, Closure $next)
101
90
* Handle the application termination.
102
91
*
103
92
* @param \Illuminate\Http\Request $request
104
- * @param mixed $response
93
+ * @param mixed $response
105
94
*
106
95
* @return void
107
96
*/
108
97
public function terminate (Request $ request , $ response ): void
109
98
{
110
99
// If there is no transaction or the HubInterface is not bound in the container there is nothing for us to do
111
- if ($ this ->transaction === null || !$ this -> app ->bound (HubInterface::class)) {
100
+ if ($ this ->transaction === null || !app () ->bound (HubInterface::class)) {
112
101
return ;
113
102
}
114
103
@@ -137,7 +126,7 @@ public function terminate(Request $request, $response): void
137
126
// dispatched using dispatch(...)->afterResponse(). This middleware is called
138
127
// before the terminating callbacks so we are 99.9% sure to be the last one
139
128
// to run except if another terminating callback is registered after ours.
140
- $ this -> app ->terminating (function () {
129
+ app () ->terminating (function () {
141
130
$ this ->finishTransaction ();
142
131
});
143
132
@@ -290,7 +279,7 @@ private function shouldRouteBeIgnored(Request $request): bool
290
279
{
291
280
// Laravel Lumen doesn't use `illuminate/routing`.
292
281
// Instead we use the route available on the request to detect if a route was matched.
293
- if ($ this -> app instanceof LumenApplication) {
282
+ if (app () instanceof LumenApplication) {
294
283
return $ request ->route () === null && config ('sentry.tracing.missing_routes ' , false ) === false ;
295
284
}
296
285
0 commit comments