@@ -339,26 +339,21 @@ const zend_function_entry nr_guzzle6_requesthandler_functions[]
339
339
nr_guzzle6_requesthandler_onrejected_arginfo ,
340
340
ZEND_ACC_PUBLIC ) PHP_FE_END };
341
341
342
- static void nr_guzzle_minit (const int guzzle_version ){
342
+ static void nr_guzzle_minit (){
343
343
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" ;
348
345
if (0 == NRINI (guzzle_enabled )) {
349
346
return ;
350
347
}
351
-
352
- INIT_CLASS_ENTRY (ce , guzzle_path ,
348
+ INIT_CLASS_ENTRY (ce , nr_guzzle_request_handler ,
353
349
nr_guzzle6_requesthandler_functions );
354
350
nr_guzzle6_requesthandler_ce
355
351
= nr_php_zend_register_internal_class_ex (& ce , NULL TSRMLS_CC );
356
-
357
352
zend_declare_property_null (nr_guzzle6_requesthandler_ce , NR_PSTR ("request" ),
358
353
ZEND_ACC_PRIVATE TSRMLS_CC );
359
354
}
360
355
361
- static void nr_guzzle_enable (const int guzzle_version ){
356
+ static void nr_guzzle_enable (){
362
357
int _retval ;
363
358
364
359
if (0 == NRINI (guzzle_enabled )) {
@@ -379,20 +374,20 @@ static void nr_guzzle_enable(const int guzzle_version){
379
374
* as a standalone file, so we can use a normal namespace declaration to
380
375
* avoid possible clashes.
381
376
*/
382
- char * eval = nr_formatf (
383
- "namespace newrelic\\Guzzle%d ;"
377
+ _retval = zend_eval_string (
378
+ "namespace newrelic\\Guzzle;"
384
379
385
380
"use Psr\\Http\\Message\\RequestInterface;"
386
381
387
382
/*
388
383
* Start by adding the outbound CAT/DT/Synthetics headers to the request.
389
384
*/
390
- "if (!function_exists('newrelic\\Guzzle%d \\middleware')) {"
385
+ "if (!function_exists('newrelic\\Guzzle\\middleware')) {"
391
386
" function middleware(callable $handler) {"
392
387
" return function (RequestInterface $request, array $options) use "
393
388
"($handler) {"
394
389
395
- " foreach (newrelic_get_request_metadata('Guzzle %d ') as $k => $v) {"
390
+ " foreach (newrelic_get_request_metadata('Guzzle') as $k => $v) {"
396
391
" $request = $request->withHeader($k, $v);"
397
392
" }"
398
393
@@ -408,19 +403,12 @@ static void nr_guzzle_enable(const int guzzle_version){
408
403
" return $promise;"
409
404
" };"
410
405
" }"
411
- "}" , guzzle_version , guzzle_version , guzzle_version );
406
+ "}" ,
407
+ NULL , "newrelic/Guzzle" TSRMLS_CC );
412
408
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 ) {
422
410
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 );
424
412
}else {
425
413
nrl_warning (NRL_FRAMEWORK ,
426
414
"%s: error evaluating PHP code; not installing handler" ,
@@ -436,6 +424,7 @@ NR_PHP_WRAPPER_START(nr_guzzle_client_construct_helper){
436
424
if (php_version_compare (version , "7" ) >= 0 ){
437
425
guzzle_version = 7 ;
438
426
}
427
+ nr_free (version );
439
428
440
429
(void )wraprec ;
441
430
NR_UNUSED_SPECIALFN ;
@@ -444,18 +433,14 @@ NR_PHP_WRAPPER_START(nr_guzzle_client_construct_helper){
444
433
* Get our middleware callable (which is just a string), and make sure it's
445
434
* actually callable before we invoke push(). (See also PHP-1184.)
446
435
*/
447
- char * str_middleware = nr_formatf ("newrelic\\Guzzle%d\\middleware" ,
448
- guzzle_version );
436
+ char * str_middleware = "newrelic\\Guzzle\\middleware" ;
449
437
zval * middleware = nr_php_zval_alloc ();
450
438
nr_php_zval_str (middleware , str_middleware );
451
- nr_free (str_middleware );
452
- nr_free (version );
453
439
454
440
if (!nr_php_is_zval_valid_callable (middleware TSRMLS_CC )) {
455
441
nrl_verbosedebug (NRL_FRAMEWORK ,
456
442
"%s: middleware string is not considered callable" ,
457
443
__func__ );
458
-
459
444
char * error_message = nr_formatf (
460
445
"Supportability/library/Guzzle %d/MiddlewareNotCallable" , guzzle_version );
461
446
nrm_force_add (NRTXN (unscoped_metrics ), error_message , 0 );
@@ -501,66 +486,28 @@ NR_PHP_WRAPPER_END
501
486
*/
502
487
#if ZEND_MODULE_API_NO >= ZEND_7_2_X_API_NO
503
488
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
-
512
489
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 ();
518
491
}
519
492
520
493
#else /* PHP < 7.2 */
521
494
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
-
529
495
void nr_guzzle7_enable (TSRMLS_D ) {
530
496
NR_UNUSED_TSRMLS
531
497
}
532
498
533
- void nr_guzzle7_minit (TSRMLS_D ) {
534
- NR_UNUSED_TSRMLS ;
535
- }
536
-
537
499
#endif /* 7.2.x */
538
500
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
-
547
501
void nr_guzzle6_enable (TSRMLS_D ) {
548
- nr_guzzle_enable (6 );
502
+ nr_guzzle_enable ();
549
503
}
550
504
551
505
void nr_guzzle6_minit (TSRMLS_D ) {
552
- nr_guzzle_minit (6 );
506
+ nr_guzzle_minit ();
553
507
}
554
508
555
509
#else /* PHP < 5.5 */
556
510
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
-
564
511
void nr_guzzle6_enable (TSRMLS_D ) {
565
512
NR_UNUSED_TSRMLS
566
513
}
0 commit comments