pxgamer/digitalocean-php

一个易于使用的PHP包装器,用于调用DigitalOcean API。

v2.1.2 2017-12-06 09:50 UTC

This package is auto-updated.

Last update: 2024-09-08 18:07:48 UTC


README

Latest Version on Packagist Software License Build Status Style CI Code Coverage Total Downloads

一个易于使用的PHP包装器,用于调用DigitalOcean API。

结构

src/
tests/
vendor/

安装

通过Composer

$ composer require pxgamer/digitalocean-php

使用方法

use \pxgamer\DigitalOcean\Client;
$client = new Client();

客户端

  • 这是主要类,用于持有CURL函数。它还包含API密钥,应首先调用。
  • 此类 必须 在其他类初始化时传递。

账户

  • 此类用于获取账户信息。

域名

  • 此类用于修改和获取域名信息。

云服务器

  • 此类用于管理多个云服务器,或管理账户下的所有云服务器。

云服务器

  • 此类用于单独管理云服务器,并提供创建快照、启用和禁用功能等功能。
// Use the specific classes as their short names
use \pxgamer\DigitalOcean;

// Create a new Client instance
$client   = new DigitalOcean\Client();
$client->setAuthKey('API_KEY');

// Initialise a new instance of each class
$account  = new DigitalOcean\Account($client);
$domains  = new DigitalOcean\Domains($client);
$droplets = new DigitalOcean\Droplets($client);
$droplet  = new DigitalOcean\Droplet($client);

方法

客户端类

/**
 * This is required to be initialised first.
 * It must be passed into all other classes.
 */
use \pxgamer\DigitalOcean\Client;
$client = new Client();
$client->setAuthKey('API_KEY');

账户类

初始化账户类

use \pxgamer\DigitalOcean\Account;
$account = new Account($client);

获取账户信息

$account->getAccount();

域名类

初始化域名类

use \pxgamer\DigitalOcean\Domains;
$domains = new Domains($client);

获取域名列表

$domains->listDomains();

获取特定域名的信息

$domains->getDomain('example.com');

创建新域名

$domains->createDomain('example.com');

删除域名

$domains->deleteDomain('example.com');

云服务器类

初始化云服务器类

// Requires the Client class to be initialised
use \pxgamer\DigitalOcean\Droplets;
$droplets = new Droplets($client);

列出云服务器

$droplets->listDroplets();

列出云服务器的邻居(同一位置的云服务器)

$droplets->listNeighbours();

云服务器类

初始化云服务器类

// Requires the Client class to be initialised
use \pxgamer\DigitalOcean\Droplet;
$droplet = new Droplet($client);

设置云服务器ID

$droplet->setDroplet('DROPLET_ID');

获取云服务器信息

// Requires the droplet ID to be set
$droplet->getDroplet();

创建云服务器

$dropletAttributes = (array)[
    'name' => 'example.com',       // Required
    'region' => 'nyc3',            // Required
    'size' => '512mb',             // Required
    'image' => 'ubuntu-14-04-x64', // Required
    'ssh_keys' => null,
    'backups' => false,
    'ipv6' => true,
    'user_data' => null,
    'private_networking' => null,
    'volume' => null,
    'tags' => [
        'web'
    ],
];

$droplet->createDroplet($dropletAttributes);

删除云服务器

// Requires the droplet ID to be set
$droplet->deleteDroplet();

列出云服务器的邻居

// Requires the droplet ID to be set
$droplet->listNeighbours();

创建快照

// Requires the droplet ID to be set
$droplet->createSnapshot('SNAPSHOT-NAME');

为云服务器启用备份

// Requires the droplet ID to be set
$droplet->enableBackups();

为云服务器禁用备份

// Requires the droplet ID to be set
$droplet->disableBackups();

重启云服务器

// Requires the droplet ID to be set
$droplet->reboot();

云服务器断电重启

// Requires the droplet ID to be set
$droplet->powerCycle();

关闭云服务器

// Requires the droplet ID to be set
$droplet->shutdown();

关闭云服务器电源

// Requires the droplet ID to be set
$droplet->powerOff();

开启云服务器电源

// Requires the droplet ID to be set
$droplet->powerOn();

调整云服务器大小

/**
 * Requires the droplet ID to be set
 *
 * Attributes:
 * - $size [string] (e.g. '1gb')
 * - $increaseDiskSize [boolean] (e.g. false) - Determines whether this is a permanent resize or not
 */

$droplet->resize('1gb', false);

重置云服务器的密码

// Requires the droplet ID to be set
$droplet->passwordReset();

重命名云服务器

// Requires the droplet ID to be set
$droplet->rename('NEW_DROPLET_NAME');

为云服务器启用IPv6

// Requires the droplet ID to be set
$droplet->enableIPv6();

为云服务器启用私有网络

// Requires the droplet ID to be set
$droplet->enablePrivateNetworking();

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

测试

$ composer test

贡献

请参阅 CONTRIBUTINGCODE_OF_CONDUCT 了解详情。

安全

如果您发现任何安全相关的问题,请发送电子邮件至 owzie123@gmail.com 而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。请参阅 许可证文件 了解更多信息。