wpcs / php-api-wrapper
一个PHP API包装器,用于轻松与WPCS.io API通信。
v1.1.0
2022-07-28 16:15 UTC
Requires
- php: >=7.1
README
一个PHP API包装器,用于轻松与WPCS.io API通信。
认证
为了使用此包,您需要通过WPCS API进行认证。您可以在控制台创建一个API密钥/密钥对,用于此包装器。
使用此包进行请求认证有两种方式:使用常量或构建函数。
使用构建函数配置认证
用于认证请求有三个函数:setRegion(string $region)
、setApiKey(string $key)
和setApiSecret(string $secret)
示例
$request = new \WPCS\API\GetTenantsRequest(); $response = $request ->setRegion('us1') // Or eu1, depending on your region. ->setApiKey('an-api-key') // The API Key you retrieved from the console ->setApiSecret('an-api-secret') // The API Secret you retrieved from the console ->send();
这允许您使用自己的密钥管理。
常量
如果您使用的是,例如,WordPress,将密钥放在wp-config.php文件中作为常量是常见的。您也可以为包装器这样做。所需的三个常量是WPCS_API_REGION
、WPCS_API_KEY
和WPCS_API_SECRET
。当它们被定义后,您不需要使用构建函数来设置认证。
示例
define('WPCS_API_REGION', 'us1'); // Or eu1, depending on your region. define('WPCS_API_KEY', 'an-api-key'); // The API Key you retrieved from the console define('WPCS_API_SECRET', 'an-api-secret'); // The API Secret you retrieved from the console // No need to set the region, API key and secret using functions now $request = new \WPCS\API\GetTenantsRequest(); $response = $request->send();
示例用法
向WPCS API发送创建新版本的请求可能如下所示(当不使用常量进行认证时)。此请求将在WPCS中的US1区域
中的产品中创建一个基于当前生产版本最后快照的版本。
$request = new \WPCS\API\CreateVersionRequest(); $response = $request ->setRegion('us1') ->setApiKey('an-api-key') ->setApiSecret('an-api-secret') ->setName('v2.0.0') ->setWordPressVersion('6.0') ->setPhpVersion('7.4') ->send();