jpollock/wp-engine-api-php
Composer 安装命令:
composer require jpollock/wp-engine-api-php
包简介
Unofficial PHP SDK for WP Engine API
README 文档
README
A PHP SDK for interacting with the WP Engine API.
Note: This SDK is maintained by Jeremy Pollock (jeremy.pollock@wpengine.com) and is not affiliated with or supported by WP Engine.
Requirements
- PHP 8.0 or higher
- Composer
- WP Engine API credentials (username and password)
Installation
Install via Composer:
composer require jpollock/wp-engine-api-php
Usage
Basic Usage
<?php use WPEngine\WPEngineSDK; // Initialize with credentials $sdk = new WPEngineSDK([ 'username' => 'your-username', 'password' => 'your-password' ]); // List sites try { $sites = $sdk->sites->listSites(); print_r($sites); } catch (\Exception $e) { echo "Error: " . $e->getMessage(); } // Get a specific site try { $site = $sdk->sites->getSite('site-id'); print_r($site); } catch (\Exception $e) { echo "Error: " . $e->getMessage(); }
Configuration
You can configure the SDK in several ways:
- Direct credentials:
$sdk = new WPEngineSDK([ 'username' => 'your-username', 'password' => 'your-password' ]);
- Configuration file:
// Load from default locations (./.env or ~/.wpengine/config) $sdk = new WPEngineSDK(); // Or specify a custom config path $sdk = new WPEngineSDK(null, '/path/to/config');
- Environment variables:
export WPENGINE_USERNAME=your-username export WPENGINE_PASSWORD=your-password
$sdk = new WPEngineSDK();
Rate Limiting
The SDK includes built-in rate limiting to prevent API quota exhaustion. You can configure the rate limit when initializing the SDK:
$sdk = new WPEngineSDK([ 'username' => 'your-username', 'password' => 'your-password' ], null, 'Default', [ 'maxRequestsPerSecond' => 5 // Default is 5 ]);
Available APIs
The SDK provides access to the following WP Engine API endpoints:
- Sites API (
$sdk->sites) - Accounts API (
$sdk->accounts) - Account Users API (
$sdk->accountUsers) - Backups API (
$sdk->backups) - Cache API (
$sdk->cache) - Domains API (
$sdk->domains) - Installs API (
$sdk->installs) - SSH Keys API (
$sdk->sshKeys) - Status API (
$sdk->status) - Users API (
$sdk->users)
Example: Managing Sites
// Create a new site try { $newSite = $sdk->sites->createSite([ 'name' => 'My New Site', 'account_id' => 'account-id' ]); print_r($newSite); } catch (\Exception $e) { echo "Error creating site: " . $e->getMessage(); } // Update a site's name try { $updatedSite = $sdk->sites->updateSite('site-id', [ 'name' => 'New Site Name' ]); print_r($updatedSite); } catch (\Exception $e) { echo "Error updating site: " . $e->getMessage(); } // Delete a site try { $sdk->sites->deleteSite('site-id'); echo "Site deleted successfully"; } catch (\Exception $e) { echo "Error deleting site: " . $e->getMessage(); }
Error Handling
The SDK throws exceptions for various error conditions:
InvalidArgumentException: For invalid parameter valuesGuzzleException: For HTTP-related errorsRateLimitException: When rate limit is exceeded
try { $sites = $sdk->sites->listSites(); } catch (\InvalidArgumentException $e) { echo "Invalid parameters: " . $e->getMessage(); } catch (\WPEngine\RateLimit\RateLimitException $e) { echo "Rate limit exceeded: " . $e->getMessage(); } catch (\GuzzleHttp\Exception\GuzzleException $e) { echo "HTTP error: " . $e->getMessage(); } catch (\Exception $e) { echo "General error: " . $e->getMessage(); }
Development
OpenAPI Generation
The SDK uses OpenAPI Generator to generate API clients from the WP Engine API specification. To regenerate the API clients:
- Install dependencies:
composer install
- Generate the API clients:
composer run-script generate-api
This will generate the API clients in src/Generated/ based on the swagger.json specification.
Project Structure
wp-engine-api-php/
├── src/
│ ├── Config/
│ │ ├── Configuration.php
│ │ └── ConfigurationManager.php
│ ├── Generated/ # OpenAPI generated code
│ │ ├── Api/ # API client classes
│ │ └── Model/ # API models
│ ├── RateLimit/
│ │ ├── RateLimiter.php
│ │ └── RateLimitException.php
│ └── WPEngineSDK.php
├── .env.example
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── openapitools.json # OpenAPI Generator config
└── swagger.json # API specification
License
This SDK is licensed under the MIT License - see the LICENSE file for details.
Maintainer
This SDK is maintained by Jeremy Pollock (jeremy.pollock@wpengine.com). For any questions, issues, or contributions, please reach out directly.
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-15