File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 36
36
},
37
37
"suggest" : {
38
38
"ext-bcmath" : " Needed to implement bolt protocol" ,
39
- "ext-json" : " Needed to implement http protocol"
39
+ "ext-json" : " Needed to implement http protocol" ,
40
+ "composer-runtime-api" : " Install composer 2 for auto detection of version in user agent"
40
41
},
41
42
"require-dev" : {
42
43
"phpunit/phpunit" : " ^9.0" ,
Original file line number Diff line number Diff line change 14
14
namespace Laudis \Neo4j \Databags ;
15
15
16
16
use function call_user_func ;
17
+ use Composer \InstalledVersions ;
18
+ use function function_exists ;
17
19
use function is_callable ;
20
+ use function sprintf ;
18
21
19
22
/**
20
23
* Configuration object for the driver.
23
26
*/
24
27
final class DriverConfiguration
25
28
{
26
- public const DEFAULT_USER_AGENT = 'neo4j-php-client/2.1.2 ' ;
29
+ public const DEFAULT_USER_AGENT = 'neo4j-php-client/%s ' ;
27
30
28
31
/** @var pure-callable():(string|null)|string|null */
29
32
private $ userAgent ;
@@ -69,7 +72,17 @@ public function getUserAgent(): string
69
72
{
70
73
$ userAgent = (is_callable ($ this ->userAgent )) ? call_user_func ($ this ->userAgent ) : $ this ->userAgent ;
71
74
72
- return $ userAgent ?? self ::DEFAULT_USER_AGENT ;
75
+ if ($ userAgent === null ) {
76
+ if (function_exists ('InstalledVersions::getPrettyVersion ' )) {
77
+ /** @psalm-suppress ImpureMethodCall */
78
+ $ version = InstalledVersions::getPrettyVersion ('laudis/neo4j-php-client ' ) ?? 'provided/replaced ' ;
79
+ } else {
80
+ $ version = '2 ' ;
81
+ }
82
+ $ userAgent = sprintf (self ::DEFAULT_USER_AGENT , $ version );
83
+ }
84
+
85
+ return $ userAgent ;
73
86
}
74
87
75
88
/**
You can’t perform that action at this time.
0 commit comments