PHP: stop reading composer.json file just to read the version string (#26156)
* PHP: remove reading from composer.json just for the version string * Be extra defensive
This commit is contained in:
parent
bba425fa11
commit
44b113b3c1
|
|
@ -22,6 +22,7 @@
|
|||
#include "channel.h"
|
||||
#include "server.h"
|
||||
#include "timeval.h"
|
||||
#include "version.h"
|
||||
#include "channel_credentials.h"
|
||||
#include "call_credentials.h"
|
||||
#include "server_credentials.h"
|
||||
|
|
@ -541,6 +542,10 @@ PHP_MINIT_FUNCTION(grpc) {
|
|||
GRPC_CHANNEL_SHUTDOWN,
|
||||
CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
/** grpc version string */
|
||||
REGISTER_STRING_CONSTANT("Grpc\\VERSION", PHP_GRPC_VERSION,
|
||||
CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
grpc_init_call(TSRMLS_C);
|
||||
GRPC_STARTUP(channel);
|
||||
grpc_init_server(TSRMLS_C);
|
||||
|
|
|
|||
|
|
@ -86,18 +86,22 @@ class BaseStub
|
|||
}
|
||||
|
||||
private static function updateOpts($opts) {
|
||||
if (!file_exists($composerFile = __DIR__.'/../../composer.json')) {
|
||||
// for grpc/grpc-php subpackage
|
||||
$composerFile = __DIR__.'/../composer.json';
|
||||
}
|
||||
$package_config = json_decode(file_get_contents($composerFile), true);
|
||||
if (!empty($opts['grpc.primary_user_agent'])) {
|
||||
$opts['grpc.primary_user_agent'] .= ' ';
|
||||
} else {
|
||||
$opts['grpc.primary_user_agent'] = '';
|
||||
}
|
||||
$opts['grpc.primary_user_agent'] .=
|
||||
'grpc-php/'.$package_config['version'];
|
||||
if (defined('\Grpc\VERSION')) {
|
||||
$version_str = \Grpc\VERSION;
|
||||
} else {
|
||||
if (!file_exists($composerFile = __DIR__.'/../../composer.json')) {
|
||||
// for grpc/grpc-php subpackage
|
||||
$composerFile = __DIR__.'/../composer.json';
|
||||
}
|
||||
$package_config = json_decode(file_get_contents($composerFile), true);
|
||||
$version_str = $package_config['version'];
|
||||
}
|
||||
$opts['grpc.primary_user_agent'] .= 'grpc-php/'.$version_str;
|
||||
if (!array_key_exists('credentials', $opts)) {
|
||||
throw new \Exception("The opts['credentials'] key is now ".
|
||||
'required. Please see one of the '.
|
||||
|
|
|
|||
Loading…
Reference in New Issue