1

サービス記述を使用して 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."
        }
    }
}

$authstring の作成に使用できるように、GetFranchiseList の「uri」値にアクセスするにはどうすればよいですか?

4

1 に答える 1

3

クライアントには、操作を含むサービス記述オブジェクトがあります。操作には、さまざまなプロパティの getter メソッドと、入力として使用される各パラメーターが含まれています。

例えば:

$client->getDescription()->getOperation('GetFranchiseList')->getUri();
于 2013-10-25T20:41:29.370 に答える