apigee/edge

Apigee Edge API 是一组通过 REST 调用与 Apigee Edge 管理服务器通信的对象,用于管理开发者、应用程序和其他实体。

1.1.22 2019-08-06 21:13 UTC

README

此库的较新 2.x 版本已发布,现在作为 Apigee Edge Client Library for PHP 可用。此库现在处于维护模式,仅接受主要错误修复。

如何使用 Apigee Edge PHP SDK

Apigee Edge 管理PHP SDK 可以轻松编写使用 Apigee Edge 管理API的PHP模块。通过使用管理PHP SDK,您可以以与 Apigee 开发者服务门户相同的方式与 Apigee Edge 通信来管理开发者、应用程序、角色和权限。

先决条件和安装要求

PHP 要求

Edge PHP SDK 有以下先决条件

  • PHP 7.1 或更高版本。这是由于 SDK 使用 PHP 命名空间、闭包和 finally 块所必需的。
  • PHP 内置的 JSON 支持。这几乎在所有默认 PHP 构建中都已启用。由于许可限制,某些 Linux 发行版(如 Debian)可能使用 JSON-C 而不是标准 JSON,这也是可以接受的。
  • PHP 内置的 CURL 支持。
  • 应安装并配置 Composer,https://getcomposer.org.cn/,并添加到您的路径中。

依赖项安装

作为基于 Composer 的项目的一部分

如果您的项目本身基于 Composer,只需将 “apigee/edge” 添加到您的项目 composer.json 文件中,并运行 composer install --no-dev。这应该将 Edge PHP SDK 以及所有其依赖项安装到您的项目的 vendor 目录中,并将其与您的项目的类自动加载器集成。如果您想运行 SDK 的单元测试,应省略 --no-dev 选项。

使用 Composer,但不是基于 Composer 的项目

如果您已安装 Composer 但选择不使用它来管理您的项目,您可以如下注册 Edge SDK 和其依赖项

$ cd path/to/edge-sdk
$ composer install --no-dev

这将从服务器下载并安装所有依赖项。您需要包含 path/to/edge-sdk/vendor/autoload.php 以利用所有类自动加载的好处。

不使用 Composer

不再支持不使用 Composer 的安装。

连接到 Edge 服务器

用于配置您与 Edge 连接的核心对象是 Apigee\Util\OrgConfig。您可以创建一个如下

<?php
// Your organization name
$org = 'my-org';
// API endpoint in Apigee’s cloud
$endpoint = 'https://api.enterprise.apigee.com/v1';
// Authenticated user for this organization.
// This user should have the ‘devadmin’ (or ‘orgadmin’) role on Edge.
$user = 'poweruser@example.com';
// Password for the above user
$pass = 'i<3apis';
// An array of other connection options
$options = array(
  'http_options' => array(
    'connection_timeout' => 4,
    'timeout' => 4
  )
);

$org_config = new Apigee\Util\OrgConfig($org, $endpoint, $user, $pass, $options);

创建 OrgConfig 对象后,您可以在构造函数中将它传递给其他对象

<?php
$developer = new Apigee\ManagementAPI\Developer($org_config);
try {
  $developer->load('user@example.com');
  $developer->setFirstName('John');
  $developer->setLastName('Doe');
  $developer->save();
  print "Developer updated!\n";
}
catch (Apigee\Exceptions\ResponseException $e) {
  print $e->getMessage();
}

$app = new Apigee\ManagementAPI\DeveloperApp($org_config, $developer->getEmail());
try {
  $app_list = $app->getListDetail();
  foreach ($app_list as $my_app) {
    print $my_app->getName() . "\n";
  }
}
catch (Apigee\Exceptions\ResponseException $e) {
  print $e->getMessage();
}