Skip to content

Commit f595c0a

Browse files
committed
feat(agent): retrieve info about installed packages
1 parent a95eb51 commit f595c0a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

agent/fw_symfony4.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "php_agent.h"
66
#include "php_call.h"
77
#include "php_error.h"
8+
#include "php_globals.h"
89
#include "php_wrapper.h"
910
#include "fw_hooks.h"
1011
#include "fw_support.h"
@@ -214,6 +215,56 @@ NR_PHP_WRAPPER(nr_symfony4_name_the_wt) {
214215
}
215216
NR_PHP_WRAPPER_END
216217

218+
void nr_get_package_information() {
219+
zval retval;
220+
int result = -1;
221+
char* func_string
222+
= ""
223+
"(function() {"
224+
" try {"
225+
" if (class_exists('Composer\\InstalledVersions')) {"
226+
" if (method_exists('Composer\\InstalledVersions', "
227+
" 'getInstalledPackages') && method_exists('Composer\\InstalledVersions', "
228+
" 'getVersion')) {"
229+
" return Composer\\InstalledVersions::getInstalledPackages();"
230+
" } else {"
231+
" return NULL;"
232+
" }"
233+
" } else {"
234+
" return NULL;"
235+
" }"
236+
" } catch (Exception $e) {"
237+
" return NULL;"
238+
" }"
239+
"})();";
240+
241+
char* getVersion = "Composer\\InstalledVersions::getVersion(\"%s\");";
242+
zend_eval_string(func_string, &retval, "Retrieve symfony package name");
243+
244+
if (result == SUCCESS) {
245+
if (Z_TYPE(retval) == IS_ARRAY) {
246+
zval* value;
247+
char buf[512];
248+
int result2;
249+
zval retval2;
250+
char* version;
251+
(void)version;
252+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(retval), value) {
253+
if (Z_TYPE_P(value) == IS_STRING) {
254+
snprintf(buf, sizeof(buf), getVersion, Z_STRVAL_P(value));
255+
result2 = zend_eval_string(buf, &retval2, "Retrieve symfony Version");
256+
if (SUCCESS == result2) {
257+
if (nr_php_is_zval_valid_string(&retval2)) {
258+
version = Z_STRVAL(retval2);
259+
}
260+
}
261+
}
262+
} ZEND_HASH_FOREACH_END();
263+
}
264+
zval_dtor(&retval);
265+
}
266+
}
267+
217268
void nr_symfony4_enable(TSRMLS_D) {
218269
/*
219270
* We set the path to 'unknown' to prevent having to name routing errors.

0 commit comments

Comments
 (0)