Skip to content

Commit 219fe3d

Browse files
ZNeumannmfulb
authored andcommitted
fix(agent): do not call 'get' directly on Symfony requests (#1151)
Calling `get` on a request object is not best practice, and has been deprecated. It is advised to instead call get on the proper member, in our case, `attributes`. closes #1148
1 parent 8b42796 commit 219fe3d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

agent/fw_symfony4.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ NR_PHP_WRAPPER_END
130130
NR_PHP_WRAPPER(nr_symfony4_name_the_wt) {
131131
zval* event = NULL;
132132
zval* request = NULL;
133+
zval* request_attrs = NULL;
134+
zval* route_rval = NULL;
135+
zval* controller_rval = NULL;
133136

134137
/* Warning avoidance */
135138
(void)wraprec;
@@ -173,9 +176,16 @@ NR_PHP_WRAPPER(nr_symfony4_name_the_wt) {
173176
request = nr_php_call(event, "getRequest");
174177
if (nr_php_object_instanceof_class(
175178
request, "Symfony\\Component\\HttpFoundation\\Request" TSRMLS_CC)) {
179+
request_attrs = nr_php_get_zval_object_property(request, "attributes");
180+
if (!nr_php_is_zval_valid_object(request_attrs)) {
181+
nrl_verbosedebug(
182+
NRL_TXN, "Symfony 4: Request->attributes could not be obtained");
183+
goto end;
184+
}
185+
176186
/* Let's look for _route first. */
177-
zval* route_rval
178-
= nr_symfony_object_get_string(request, "_route" TSRMLS_CC);
187+
route_rval
188+
= nr_symfony_object_get_string(request_attrs, "_route" TSRMLS_CC);
179189

180190
if (route_rval) {
181191
if (NR_SUCCESS
@@ -187,8 +197,8 @@ NR_PHP_WRAPPER(nr_symfony4_name_the_wt) {
187197
nr_php_zval_free(&route_rval);
188198
} else {
189199
/* No _route. Look for _controller. */
190-
zval* controller_rval
191-
= nr_symfony_object_get_string(request, "_controller" TSRMLS_CC);
200+
controller_rval
201+
= nr_symfony_object_get_string(request_attrs, "_controller" TSRMLS_CC);
192202

193203
if (controller_rval) {
194204
if (NR_SUCCESS

0 commit comments

Comments
 (0)