@@ -21,13 +21,22 @@ static bool nr_execute_handle_autoload_composer_is_initialized() {
21
21
};
22
22
23
23
// the class is found - there's hope!
24
+ #if 0
24
25
if (NULL == nr_php_find_class_method (zce , "getinstalledpackages" )
25
26
|| NULL == nr_php_find_class_method (zce , "getversion" )) {
26
27
nrl_verbosedebug (
27
28
NRL_INSTRUMENT ,
28
29
"Composer\\InstalledVersions class found, but methods not found" );
29
30
return false;
30
31
}
32
+ #else
33
+ if (NULL == nr_php_find_class_method (zce , "getallrawdata" )) {
34
+ nrl_verbosedebug (
35
+ NRL_INSTRUMENT ,
36
+ "Composer\\InstalledVersions class found, but methods not found" );
37
+ return false;
38
+ }
39
+ #endif
31
40
32
41
return true;
33
42
}
@@ -93,9 +102,11 @@ static int nr_execute_handle_autoload_composer_init(const char* vendor_path) {
93
102
94
103
static void nr_execute_handle_autoload_composer_get_packages_information (
95
104
const char * vendor_path ) {
96
- zval retval ;
105
+ zval retval ; // This is used as a return value for zend_eval_string.
106
+ // It will only be set if the result of the eval is SUCCESS.
97
107
int result = -1 ;
98
108
109
+ #if 0
99
110
char * getpackagename
100
111
= ""
101
112
"(function() {"
@@ -119,6 +130,25 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
119
130
" return NULL;"
120
131
" }"
121
132
"})();" ;
133
+ #else
134
+ char * getallrawdata
135
+ = ""
136
+ "(function() {"
137
+ " try {"
138
+ " $packages = array();"
139
+ " foreach (\\Composer\\InstalledVersions::getAllRawData() as $installed) { "
140
+ " foreach ($installed['versions'] as $packageName => $packageData) {"
141
+ " if (isset($packageData['pretty_version'])) {"
142
+ " $packages[$packageName] = ltrim($packageData['pretty_version'], 'v');"
143
+ " }"
144
+ " }"
145
+ " }"
146
+ " return $packages;"
147
+ " } catch (Exception $e) {"
148
+ " return NULL;"
149
+ " }"
150
+ "})();" ;
151
+ #endif
122
152
123
153
if (NR_SUCCESS != nr_execute_handle_autoload_composer_init (vendor_path )) {
124
154
nrl_debug (NRL_INSTRUMENT ,
@@ -131,7 +161,7 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
131
161
nrl_verbosedebug (NRL_INSTRUMENT , "%s - Composer runtime API available" ,
132
162
__func__ );
133
163
134
- #if 1
164
+ #if 0
135
165
result = zend_eval_string (getpackagename , & retval ,
136
166
"get installed packages by name" TSRMLS_CC );
137
167
if (result == SUCCESS ) {
@@ -179,15 +209,37 @@ static void nr_execute_handle_autoload_composer_get_packages_information(
179
209
zval_dtor (& retval );
180
210
}
181
211
#else
182
- zv = nr_php_call (NULL , "Composer\\InstalledVersions::getInstalledPackages" ,
183
- NULL );
184
- if (NULL != zv ) {
185
- char strbuf [NR_EXECUTE_DEBUG_STRBUFSZ ];
186
- nr_format_zval_for_debug (zv , strbuf , 0 , NR_EXECUTE_DEBUG_STRBUFSZ - 1 , 0 );
187
- nrl_always ("Composer\\InstalledVersions::getInstalledPackages()=%s" ,
188
- strbuf );
189
- nr_php_zval_free (& zv );
212
+ result = zend_eval_string (getallrawdata , & retval , "composer_getallrawdata.php" );
213
+ if (SUCCESS != result ) {
214
+ nrl_verbosedebug (NRL_INSTRUMENT , "%s - composer_getallrawdata.php failed" , __func__ );
215
+ return ;
216
+ }
217
+ if (IS_ARRAY == Z_TYPE (retval )) {
218
+ zend_string * package_name = NULL ;
219
+ zval * package_version = NULL ;
220
+ ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL (retval ), package_name , package_version ) {
221
+ if (NULL == package_name || NULL == package_version ) {
222
+ continue ;
223
+ }
224
+ if (nr_php_is_zval_non_empty_string (package_version )) {
225
+ nrl_verbosedebug (NRL_INSTRUMENT , "package %s, version %s" ,
226
+ NRSAFESTR (ZSTR_VAL (package_name )),
227
+ NRSAFESTR (Z_STRVAL_P (package_version )));
228
+ if (NRINI (vulnerability_management_package_detection_enabled )) {
229
+ nr_txn_add_php_package (NRPRG (txn ), NRSAFESTR (ZSTR_VAL (package_name )),
230
+ NRSAFESTR (Z_STRVAL_P (package_version )));
231
+ }
232
+ nr_fw_support_add_package_supportability_metric (
233
+ NRPRG (txn ), NRSAFESTR (ZSTR_VAL (package_name )),
234
+ NRSAFESTR (Z_STRVAL_P (package_version )));
235
+ }
236
+ }
237
+ ZEND_HASH_FOREACH_END ();
238
+ } else {
239
+ nrl_verbosedebug (NRL_INSTRUMENT ,
240
+ "%s - installed packages is not an array" , __func__ );
190
241
}
242
+ zval_dtor (& retval );
191
243
#endif
192
244
}
193
245
0 commit comments