Skip to content

Commit 40ab8cf

Browse files
committed
fix(agent): remove guzzle version from namespace
1 parent 8065805 commit 40ab8cf

File tree

2 files changed

+17
-71
lines changed

2 files changed

+17
-71
lines changed

agent/lib_guzzle6.c

+17-70
Original file line numberDiff line numberDiff line change
@@ -339,26 +339,21 @@ const zend_function_entry nr_guzzle6_requesthandler_functions[]
339339
nr_guzzle6_requesthandler_onrejected_arginfo,
340340
ZEND_ACC_PUBLIC) PHP_FE_END};
341341

342-
static void nr_guzzle_minit(const int guzzle_version){
342+
static void nr_guzzle_minit(){
343343
zend_class_entry ce;
344-
char guzzle_path[] = "newrelic\\Guzzle6\\RequestHandler";
345-
if (guzzle_version == 7){
346-
nr_strcpy(guzzle_path, "newrelic\\Guzzle7\\RequestHandler");
347-
}
344+
char nr_guzzle_request_handler[] = "newrelic\\Guzzle\\RequestHandler";
348345
if (0 == NRINI(guzzle_enabled)) {
349346
return;
350347
}
351-
352-
INIT_CLASS_ENTRY(ce, guzzle_path,
348+
INIT_CLASS_ENTRY(ce, nr_guzzle_request_handler,
353349
nr_guzzle6_requesthandler_functions);
354350
nr_guzzle6_requesthandler_ce
355351
= nr_php_zend_register_internal_class_ex(&ce, NULL TSRMLS_CC);
356-
357352
zend_declare_property_null(nr_guzzle6_requesthandler_ce, NR_PSTR("request"),
358353
ZEND_ACC_PRIVATE TSRMLS_CC);
359354
}
360355

361-
static void nr_guzzle_enable(const int guzzle_version){
356+
static void nr_guzzle_enable(){
362357
int _retval;
363358

364359
if (0 == NRINI(guzzle_enabled)) {
@@ -379,20 +374,20 @@ static void nr_guzzle_enable(const int guzzle_version){
379374
* as a standalone file, so we can use a normal namespace declaration to
380375
* avoid possible clashes.
381376
*/
382-
char *eval = nr_formatf(
383-
"namespace newrelic\\Guzzle%d;"
377+
_retval = zend_eval_string(
378+
"namespace newrelic\\Guzzle;"
384379

385380
"use Psr\\Http\\Message\\RequestInterface;"
386381

387382
/*
388383
* Start by adding the outbound CAT/DT/Synthetics headers to the request.
389384
*/
390-
"if (!function_exists('newrelic\\Guzzle%d\\middleware')) {"
385+
"if (!function_exists('newrelic\\Guzzle\\middleware')) {"
391386
" function middleware(callable $handler) {"
392387
" return function (RequestInterface $request, array $options) use "
393388
"($handler) {"
394389

395-
" foreach (newrelic_get_request_metadata('Guzzle %d') as $k => $v) {"
390+
" foreach (newrelic_get_request_metadata('Guzzle') as $k => $v) {"
396391
" $request = $request->withHeader($k, $v);"
397392
" }"
398393

@@ -408,19 +403,12 @@ static void nr_guzzle_enable(const int guzzle_version){
408403
" return $promise;"
409404
" };"
410405
" }"
411-
"}", guzzle_version, guzzle_version, guzzle_version);
406+
"}",
407+
NULL, "newrelic/Guzzle" TSRMLS_CC);
412408

413-
char *guzzle_ver = nr_formatf("newrelic/Guzzle%d", guzzle_version);
414-
_retval = zend_eval_string(eval, NULL, guzzle_ver TSRMLS_CC);
415-
nr_free(eval);
416-
nr_free(guzzle_ver);
417-
418-
if (SUCCESS == _retval && guzzle_version == 6) {
419-
nr_php_wrap_user_function(NR_PSTR("GuzzleHttp\\Client::__construct"),
420-
nr_guzzle6_client_construct TSRMLS_CC);
421-
}else if (SUCCESS == _retval && guzzle_version == 7){
409+
if (SUCCESS == _retval) {
422410
nr_php_wrap_user_function(NR_PSTR("GuzzleHttp\\Client::__construct"),
423-
nr_guzzle7_client_construct TSRMLS_CC);
411+
nr_guzzle_client_construct_helper TSRMLS_CC);
424412
}else {
425413
nrl_warning(NRL_FRAMEWORK,
426414
"%s: error evaluating PHP code; not installing handler",
@@ -436,6 +424,7 @@ NR_PHP_WRAPPER_START(nr_guzzle_client_construct_helper){
436424
if (php_version_compare(version, "7") >= 0){
437425
guzzle_version = 7;
438426
}
427+
nr_free(version);
439428

440429
(void)wraprec;
441430
NR_UNUSED_SPECIALFN;
@@ -444,18 +433,14 @@ NR_PHP_WRAPPER_START(nr_guzzle_client_construct_helper){
444433
* Get our middleware callable (which is just a string), and make sure it's
445434
* actually callable before we invoke push(). (See also PHP-1184.)
446435
*/
447-
char *str_middleware = nr_formatf("newrelic\\Guzzle%d\\middleware",
448-
guzzle_version);
436+
char *str_middleware = "newrelic\\Guzzle\\middleware";
449437
zval* middleware = nr_php_zval_alloc();
450438
nr_php_zval_str(middleware, str_middleware);
451-
nr_free(str_middleware);
452-
nr_free(version);
453439

454440
if (!nr_php_is_zval_valid_callable(middleware TSRMLS_CC)) {
455441
nrl_verbosedebug(NRL_FRAMEWORK,
456442
"%s: middleware string is not considered callable",
457443
__func__);
458-
459444
char* error_message = nr_formatf(
460445
"Supportability/library/Guzzle %d/MiddlewareNotCallable", guzzle_version);
461446
nrm_force_add(NRTXN(unscoped_metrics), error_message, 0);
@@ -501,66 +486,28 @@ NR_PHP_WRAPPER_END
501486
*/
502487
#if ZEND_MODULE_API_NO >= ZEND_7_2_X_API_NO
503488

504-
NR_PHP_WRAPPER_START(nr_guzzle7_client_construct){
505-
NR_PHP_WRAPPER_DELEGATE(nr_guzzle_client_construct_helper);
506-
(void)wraprec;
507-
NR_UNUSED_SPECIALFN;
508-
NR_PHP_WRAPPER_CALL;
509-
}
510-
NR_PHP_WRAPPER_END
511-
512489
void nr_guzzle7_enable(TSRMLS_D) {
513-
nr_guzzle_enable(7);
514-
}
515-
516-
void nr_guzzle7_minit(TSRMLS_D) {
517-
nr_guzzle_minit(7);
490+
nr_guzzle_enable();
518491
}
519492

520493
#else /* PHP < 7.2 */
521494

522-
NR_PHP_WRAPPER_START(nr_guzzle7_client_construct) {
523-
(void)wraprec;
524-
NR_UNUSED_SPECIALFN;
525-
NR_UNUSED_TSRMLS;
526-
}
527-
NR_PHP_WRAPPER_END
528-
529495
void nr_guzzle7_enable(TSRMLS_D) {
530496
NR_UNUSED_TSRMLS
531497
}
532498

533-
void nr_guzzle7_minit(TSRMLS_D) {
534-
NR_UNUSED_TSRMLS;
535-
}
536-
537499
#endif /* 7.2.x */
538500

539-
NR_PHP_WRAPPER_START(nr_guzzle6_client_construct) {
540-
NR_PHP_WRAPPER_DELEGATE(nr_guzzle_client_construct_helper);
541-
(void)wraprec;
542-
NR_UNUSED_SPECIALFN;
543-
NR_PHP_WRAPPER_CALL;
544-
}
545-
NR_PHP_WRAPPER_END
546-
547501
void nr_guzzle6_enable(TSRMLS_D) {
548-
nr_guzzle_enable(6);
502+
nr_guzzle_enable();
549503
}
550504

551505
void nr_guzzle6_minit(TSRMLS_D) {
552-
nr_guzzle_minit(6);
506+
nr_guzzle_minit();
553507
}
554508

555509
#else /* PHP < 5.5 */
556510

557-
NR_PHP_WRAPPER_START(nr_guzzle6_client_construct) {
558-
(void)wraprec;
559-
NR_UNUSED_SPECIALFN;
560-
NR_UNUSED_TSRMLS;
561-
}
562-
NR_PHP_WRAPPER_END
563-
564511
void nr_guzzle6_enable(TSRMLS_D) {
565512
NR_UNUSED_TSRMLS
566513
}

agent/php_minit.c

-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ PHP_MINIT_FUNCTION(newrelic) {
635635

636636
nr_guzzle4_minit(TSRMLS_C);
637637
nr_guzzle6_minit(TSRMLS_C);
638-
nr_guzzle7_minit(TSRMLS_C);
639638
nr_laravel_minit(TSRMLS_C);
640639
nr_php_set_opcode_handlers();
641640

0 commit comments

Comments
 (0)