@@ -30,15 +30,15 @@ class Integration implements IntegrationInterface
30
30
*/
31
31
public function setupOnce (): void
32
32
{
33
- Scope::addGlobalEventProcessor (function (Event $ event ): Event {
33
+ Scope::addGlobalEventProcessor (static function (Event $ event ): Event {
34
34
$ self = SentrySdk::getCurrentHub ()->getIntegration (self ::class);
35
35
36
36
if (!$ self instanceof self) {
37
37
return $ event ;
38
38
}
39
39
40
40
if (empty ($ event ->getTransaction ())) {
41
- $ event ->setTransaction ($ self-> getTransaction ());
41
+ $ event ->setTransaction (self :: getTransaction ());
42
42
}
43
43
44
44
return $ event ;
@@ -121,52 +121,64 @@ public static function flushEvents(): void
121
121
*
122
122
* @param \Illuminate\Routing\Route $route
123
123
*
124
- * @return string|null
124
+ * @return string
125
125
*/
126
- public static function extractNameForRoute (Route $ route ): ? string
126
+ public static function extractNameForRoute (Route $ route ): string
127
127
{
128
128
$ routeName = null ;
129
129
130
- if (empty ($ routeName ) && $ route ->getName ()) {
131
- // someaction (route name/alias)
132
- $ routeName = $ route ->getName ();
133
-
134
- // Laravel 7 route caching generates a route names if the user didn't specify one
135
- // theirselfs to optimize route matching. These route names are useless to the
136
- // developer so if we encounter a generated route name we discard the value
137
- if (Str::contains ($ routeName , 'generated:: ' )) {
138
- $ routeName = null ;
139
- }
140
-
141
- // If the route name ends with a `.` we assume an incomplete group name prefix
142
- // we discard this value since it will most likely not mean anything to the
143
- // developer and will be duplicated by other unnamed routes in the group
144
- if (Str::endsWith ($ routeName , '. ' )) {
145
- $ routeName = null ;
146
- }
130
+ // someaction (route name/alias)
131
+ if ($ route ->getName ()) {
132
+ $ routeName = self ::extractNameForNamedRoute ($ route ->getName ());
147
133
}
148
134
135
+ // Some\Controller@someAction (controller action)
149
136
if (empty ($ routeName ) && $ route ->getActionName ()) {
150
- // Some\Controller@someAction (controller action)
151
- $ routeName = ltrim ($ route ->getActionName (), '\\' );
152
-
153
- $ baseNamespace = self ::$ baseControllerNamespace ?? '' ;
154
-
155
- // Strip away the base namespace from the action name
156
- if (!empty ($ baseNamespace )) {
157
- // @see: Str::after, but this is not available before Laravel 5.4 so we use a inlined version
158
- $ routeName = array_reverse (explode ($ baseNamespace . '\\' , $ routeName , 2 ))[0 ];
159
- }
137
+ $ routeName = self ::extractNameForActionRoute ($ route ->getActionName ());
160
138
}
161
139
140
+ // /someaction // Fallback to the url
162
141
if (empty ($ routeName ) || $ routeName === 'Closure ' ) {
163
- // /someaction // Fallback to the url
164
142
$ routeName = '/ ' . ltrim ($ route ->uri (), '/ ' );
165
143
}
166
144
167
145
return $ routeName ;
168
146
}
169
147
148
+ private static function extractNameForNamedRoute (string $ routeName ): ?string
149
+ {
150
+ // Laravel 7 route caching generates a route names if the user didn't specify one
151
+ // theirselfs to optimize route matching. These route names are useless to the
152
+ // developer so if we encounter a generated route name we discard the value
153
+ if (Str::contains ($ routeName , 'generated:: ' )) {
154
+ return null ;
155
+ }
156
+
157
+ // If the route name ends with a `.` we assume an incomplete group name prefix
158
+ // we discard this value since it will most likely not mean anything to the
159
+ // developer and will be duplicated by other unnamed routes in the group
160
+ if (Str::endsWith ($ routeName , '. ' )) {
161
+ return null ;
162
+ }
163
+
164
+ return $ routeName ;
165
+ }
166
+
167
+ private static function extractNameForActionRoute (string $ actionName ): string
168
+ {
169
+ $ routeName = ltrim ($ actionName , '\\' );
170
+
171
+ $ baseNamespace = self ::$ baseControllerNamespace ?? '' ;
172
+
173
+ if (empty ($ baseNamespace )) {
174
+ return $ routeName ;
175
+ }
176
+
177
+ // Strip away the base namespace from the action name
178
+ // @see: Str::after, but this is not available before Laravel 5.4 so we use a inlined version
179
+ return array_reverse (explode ($ baseNamespace . '\\' , $ routeName , 2 ))[0 ];
180
+ }
181
+
170
182
/**
171
183
* Retrieve the meta tags with tracing information to link this request to front-end requests.
172
184
*
0 commit comments