vizuaalog / pterodactyl-php
Pterodactyl 游戏面板的非官方 PHP API 客户端。
1.0.3
2020-01-01 18:10 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- larapack/dd: 1.*
This package is auto-updated.
Last update: 2024-08-30 01:06:05 UTC
README
Pterodactyl PHP 是 Pterodactyl 游戏面板的非官方 PHP API 客户端。它采用面向对象的方法,以更智能的方式执行更新。此包主要针对项目需求编写,但我尽量使其尽可能通用,以便其他人也能使用。
此版本已在 Pterodactyl 0.7.16 上进行测试
代码已进行文档记录,任何好的 IDE 都应该能够帮助完成自动补全。
安装
由于 composer 的支持,安装非常简单。只需运行 composer install vizuaalog/pterodactyl-php
。
使用
这假设您已经在项目中设置了 composer,以便允许使用 use
语句。
一切从主要的 Pterodactyl
类开始
use VizuaaLOG\Pterodactyl\Pterodactyl; $panel = new Pterodactyl(string $api_key, string $base_uri, string $type = 'application');
$api_key
(字符串) - 这应该是通过面板管理部分或用户部分生成的 API 密钥$base_uri
(字符串) - 这是面板的基本 URI。例如 'https://pterodactyl.app'$type
(字符串,默认application
) - 这是您希望使用的 API 路由类型。如果您从用户部分提供 API 密钥,则将其设置为client
,否则默认的application
即可。
提供给创建或更新方法的所有值都符合 Pterodactyl API 的精确要求,建议查看相关文档。
直接在资源上调用更新方法将在可能的情况下提供帮助,并预先填充您未传递的任何所需字段。例如,只想更新服务器的名称 - Pterodactyl 需要提供比名称更多的信息,所以这将在幕后完成。
一些方法有两种不同的变体,第一种是如果您已经有了资源对象,有助于提高可读性。第二种是如果您只有 ID 而不想先获取资源详细信息。
服务器
以下是管理服务器的可用方法。
// Returns an array of Server objects. $servers = $panel->servers->all(); // Returns a single Server object // If using the client mode, then this should be the string identifier instead // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $server = $panel->servers->get(int|string $server_id, string[] $includes); // Returns a single Server object $server = $panel->servers->getByExternalId(string $external_id, string[] $includes); // Returns a single Server object if successful, throws exception on error $server = $panel->servers->create(array $data); // Update a server's details // Returns the updated Server object $server->update(array $data); $panel->servers->update(int $server_id, array $data); // Update a server's build configuration // Returns the updated Server object $server->updateBuild(array $data); $panel->servers->updateBuild(int $server_id, array $data); // Update a server's startup configuration // Returns the updated server object $server->updateStartup(array $data); $panel->servers->updateStartup(int $server_id, array $data); // Suspend a server // Returns true if successful, false otherwise $server->suspend(); $panel->servers->suspend(int $server_id); // Unsuspend a server // Returns true if successful, false otherwise $server->unsuspend(); $panel->servers->unsuspend(int $server_id); // Reinstall a server // Returns true if successful, false otherwise $server->reinstall(); $panel->servers->reinstall(int $server_id); // Rebuild a server // Returns true is successful, false otherwise $server->rebuild(); $panel->servers->rebuild(int $server_id); // Delete a server // Returns true if successful, false otherwise $server->delete(bool $force = false); $panel->servers->delete(int $server_id, bool $force = false); // Get all databases for a server // Returns an array of ServerDatabase objects $server->databases(); $panel->servers->databases(int $server_id); // Get a database for a server // Returns a single ServerDatabase object $server->database(int $database_id); $panel->servers->database(int $server_id, int $database_id); // Create a database for a server // Returns a single ServerDatabase object $server->createDatabase(array $data); $panel->servers->createDatabase(int $server_id, array $data); // Reset a database's password // Returns true on success, false otherwise $server->resetDatabasePassword(int $database_id); $panel->servers->resetDatabasePassword(int $server_id, int $database_id); // Delete a database // Returns true on success, false otherwise $server->deleteDatabase(int $database_id); $panel->servers->deleteDatabase(int $database_id);
用户
以下是管理用户的可用方法。
// Get all users // Returns an array of User objects $users = $panel->users->all(); // Get a single user // Returns a single User object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $user = $panel->users->get(int $user_id, string[] $includes); // Get a single user by external id // Returns a single User object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $user = $panel->users->getByExternalId(string $external_id, string[] $includes); // Create a user // Returns the created User object $user = $panel->users->create(array $data); // Edit a user // Returns the updated User object $user->update(array $data); $panel->users->update(int $user_id, array $data); // Delete a user // Returns true on success, false otherwise $user->delete(); $panel->users->delete(int $user_id);
节点
以下是管理节点的可用方法。
// Get all nodes // Returns an array of Node objects $nodes = $panel->nodes->all(); // Get a single node // Returns a single Node object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $node = $panel->nodes->get(int $node_id, string[] $includes); // Create a node // Returns the created Node object $node = $panel->nodes->create(array $data); // Edit a node // Returns the updated Node object $node->update(array $data); $panel->nodes->update(int $node_id, array $data); // Delete a node // Returns true on success, false otherwise $node->delete(); $panel->nodes->delete(int $node_id); // Get a node's allocations // Returns an array of Allocation objects $allocations = $node->allocations(); $allocations = $panel->nodes->allocations(int $node_id); // Create a new allocation // Returns the newly created Allocation object $allocation = $node->createAllocation(array $data); $allocation = $panel->nodes->createAllocation(int $node_id, array $data); // Delete an allocation // Returns true on success, false otherwise $node->deleteAllocation(int $allocation_id); $panel->nodes->deleteAllocation(int $node_id, int $allocation_id);
位置
以下是管理位置的可用方法。
// Get all locations // Returns an array of Node objects $locations = $panel->locations->all(); // Get a single location // Returns a single Location object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $location = $panel->locations->get(int $location_id, string[] $includes); // Create a location // Returns the created Location object $location = $panel->locations->create(array $data); // Edit a location // Returns the updated Location object $location->update(array $data); $panel->locations->update(int $location_id, array $data); // Delete a location // Returns true on success, false otherwise $location->delete(); $panel->locations->delete(int $location_id);
巢/蛋
以下是管理巢和蛋的可用方法。
// Get all nests // Returns an array of Nest objects $nests = $panel->nests->all(); // Get a single nest // Returns a single Nest object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $nest = $panel->nests->get(int $nest_id, string[] $includes); // Get all eggs for a nest // Returns an array of Egg objects $eggs = $nest->eggs(); $nests = $panel->nests->eggs(int $nest_id); // Get a single egg from a nest // Returns a single Egg object // $includes is an array of strings representing additional data to include in the same request, see Pterodactyl API docs for these. $egg = $nest->egg(int $egg_id, string[] $includes = ['variabled']); $egg = $panel->nests->egg(int $nest_id, int $egg_id, string[] $includes = ['variables']);
异常
- 向 Pterodactyl 构造函数提供没有 API 密钥将引发 InvalidApiKeyException。
- 向 Pterodactyl 构造函数提供没有基本 URI 将引发 InvalidBaseUriException。
- 如果 Pterodactyl 返回异常错误,则大多数方法将引发 PterodactylRequestException,此异常将包含从面板发送的一些信息,以帮助诊断问题。
- 在某些情况下,可能会抛出 GuzzelException、ClientException 或 ServerException,这表明与面板通信出现问题。在大多数情况下,这些都会转换为 PterodactylRequestException,所以这种情况不应该经常发生。