|
8 | 8 | #include "php_user_instrument.h"
|
9 | 9 | #include "php_hash.h"
|
10 | 10 | #include "php_wrapper.h"
|
| 11 | +#include "php_execute.h" |
| 12 | +#include "php_globals.h" |
11 | 13 | #include "lib_guzzle_common.h"
|
12 | 14 | #include "lib_guzzle4.h"
|
13 | 15 | #include "lib_guzzle6.h"
|
| 16 | +#include "fw_laravel.h" |
| 17 | +#include "fw_laravel_queue.h" |
| 18 | +#include "fw_support.h" |
| 19 | +#include "php_error.h" |
14 | 20 | #include "nr_header.h"
|
15 | 21 | #include "util_logging.h"
|
16 | 22 | #include "util_memory.h"
|
17 | 23 | #include "util_strings.h"
|
18 | 24 |
|
| 25 | +int php_version_compare(char*, char*); |
| 26 | + |
19 | 27 | char* nr_guzzle_create_async_context_name(const char* prefix, const zval* obj) {
|
20 | 28 | if (!nr_php_is_zval_valid_object(obj)) {
|
21 | 29 | return NULL;
|
@@ -74,9 +82,44 @@ int nr_guzzle_in_call_stack(TSRMLS_D) {
|
74 | 82 | return in_guzzle;
|
75 | 83 | }
|
76 | 84 |
|
77 |
| -int nr_guzzle_does_zval_implement_has_emitter(zval* obj TSRMLS_DC) { |
78 |
| - return nr_php_object_instanceof_class( |
79 |
| - obj, "GuzzleHttp\\Event\\HasEmitterInterface" TSRMLS_CC); |
| 85 | +extern char* nr_guzzle_version(zval* obj TSRMLS_DC) { |
| 86 | + char* retval = NULL; |
| 87 | + zval* version = NULL; |
| 88 | + zend_class_entry* ce = NULL; |
| 89 | + |
| 90 | + if (0 == nr_php_is_zval_valid_object(obj)) { |
| 91 | + nrl_verbosedebug(NRL_FRAMEWORK, "%s: Application object is invalid", |
| 92 | + __func__); |
| 93 | + return NULL; |
| 94 | + } |
| 95 | + |
| 96 | + ce = Z_OBJCE_P(obj); |
| 97 | + if (NULL == ce) { |
| 98 | + nrl_verbosedebug(NRL_FRAMEWORK, "%s: Application has NULL class entry", |
| 99 | + __func__); |
| 100 | + return NULL; |
| 101 | + } |
| 102 | + |
| 103 | + if (nr_php_get_class_constant(ce, "VERSION") == NULL){ |
| 104 | + version = nr_php_get_class_constant(ce, "MAJOR_VERSION"); |
| 105 | + } else { |
| 106 | + version = nr_php_get_class_constant(ce, "VERSION"); |
| 107 | + } |
| 108 | + if (NULL == version) { |
| 109 | + nrl_verbosedebug(NRL_FRAMEWORK, "%s: Application does not have VERSION", |
| 110 | + __func__); |
| 111 | + return NULL; |
| 112 | + } |
| 113 | + |
| 114 | + if (nr_php_is_zval_valid_string(version)) { |
| 115 | + retval = nr_strndup(Z_STRVAL_P(version), Z_STRLEN_P(version)); |
| 116 | + } else { |
| 117 | + nrl_verbosedebug(NRL_FRAMEWORK, |
| 118 | + "%s: expected VERSION be a valid string, got type %d", |
| 119 | + __func__, Z_TYPE_P(version)); |
| 120 | + } |
| 121 | + nr_php_zval_free(&version); |
| 122 | + return retval; |
80 | 123 | }
|
81 | 124 |
|
82 | 125 | nr_segment_t* nr_guzzle_obj_add(const zval* obj,
|
@@ -272,19 +315,20 @@ char* nr_guzzle_response_get_header(const char* header,
|
272 | 315 | }
|
273 | 316 |
|
274 | 317 | NR_PHP_WRAPPER_START(nr_guzzle_client_construct) {
|
275 |
| - int is_guzzle_45 = 0; |
276 | 318 | zval* this_var = nr_php_scope_get(NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
|
| 319 | + char *version = NULL; |
| 320 | + version = nr_guzzle_version(this_var TSRMLS_CC); |
277 | 321 |
|
278 | 322 | (void)wraprec;
|
279 | 323 | NR_UNUSED_SPECIALFN;
|
280 |
| - |
281 |
| - is_guzzle_45 = nr_guzzle_does_zval_implement_has_emitter(this_var TSRMLS_CC); |
282 | 324 | nr_php_scope_release(&this_var);
|
283 |
| - |
284 |
| - if (is_guzzle_45) { |
285 |
| - NR_PHP_WRAPPER_DELEGATE(nr_guzzle4_client_construct); |
286 |
| - } else { |
| 325 | + |
| 326 | + if (php_version_compare(version, "7") >= 0){ |
| 327 | + NR_PHP_WRAPPER_DELEGATE(nr_guzzle7_client_construct); |
| 328 | + } else if (php_version_compare(version, "6") >= 0) { |
287 | 329 | NR_PHP_WRAPPER_DELEGATE(nr_guzzle6_client_construct);
|
| 330 | + } else{ |
| 331 | + NR_PHP_WRAPPER_DELEGATE(nr_guzzle4_client_construct); |
288 | 332 | }
|
289 | 333 | }
|
290 | 334 | NR_PHP_WRAPPER_END
|
0 commit comments