我正在使用服务描述创建一个 Guzzle 客户端。服务描述中的每个操作都包含一个 URI。我正在访问的 REST 端点需要一个授权标头,该标头是通过将公钥和端点的 uri 粘在一起,然后从结果字符串创建一个 md5 来制作的。这用作授权值。
在实例化客户端后,我不知道如何从服务描述中获取 uri 值。
我正在像这样创建 Guzzle 客户端:
class RestClient extends Client
{
public static function factory($config = array())
{
// The following values are required when creating the client
$required = array(
'base_url',
'public_key',
'private_key'
);
$path = drupal_get_path('module', 'junkrest');
// Merge in default settings and validate the config
$config = Collection::fromConfig($config, $required);
// Create a new client
$client = new self($config->get('base_url'), $config);
// Set the service description
$client->setDescription(ServiceDescription::factory($path . '/config/services.json'));
$authstring = md5($public_key, 'the uri value from an operation in the services.json file');
$client->setDefaultHeaders(array(
'Authentication' => $authstring));
return $client;
}
}
The services.json file contains this:
{
"name": "TheName",
"apiVersion": "1",
"baseUrl": "https://apidev.example.com",
"description": "Custom REST API client",
"operations": {
"GetFranchiseList": {
"httpMethod": "GET",
"uri": "v1/franchise",
"summary": "Returns an array of franchises."
},
"GetReviews": {
"httpMethod": "GET",
"uri": "v1/review",
"summary": "Returns an array of reviews."
}
}
}
如何访问 GetFranchiseList 中的 'uri' 值,以便我可以使用它来创建 $authstring?