pxgamer/digitalocean-php

An easy to use wrapper for the DigitalOcean API written in PHP.

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

This package is auto-updated.

Last update: 2024-12-08 18:36:15 UTC


README

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

An easy to use wrapper for the DigitalOcean API written in PHP.

Structure

src/
tests/
vendor/

Install

Via Composer

$ composer require pxgamer/digitalocean-php

Usage

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

Classes

Client

  • This is the main class and is used to hold the CURL functions. It also contains the API key, and should be called first.
  • This class must be passed to other classes upon their initialisation.

Account

  • This class is used to retrieve account information.

Domains

  • This class is used to modify and retrieve domain information.

Droplets

  • This class is used to manage multiple droplets, or all droplets for an account.

Droplet

  • This class is used to manage droplets individually and can provides functions such as creating snapshots, enabling and disabling features, etc.
// 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);

Methods

Client Class

/**
 * 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');

Account Class

Initialise Account Class

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

Getting Account Information

$account->getAccount();

Domains Class

Initialise Domains Class

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

Getting a list of domains

$domains->listDomains();

Getting information for a specific domain

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

Create a new domain

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

Deleting a domain

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

Droplets Class

Initialise Droplets Class

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

Listing droplets

$droplets->listDroplets();

Listing neighbours of Droplets (droplets in the same location)

$droplets->listNeighbours();

Droplet Class

Initialise Droplet Class

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

Setting the Droplet ID

$droplet->setDroplet('DROPLET_ID');

Getting information about a droplet

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

Creating a Droplet

$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);

Deleting a Droplet

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

Listing a Droplet's neighbours

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

Create a snapshot

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

Enabling backups for a Droplet

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

Disabling backups for a Droplet

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

Rebooting a Droplet

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

Power Cycling a Droplet

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

Shutting down a Droplet

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

Powering off a Droplet

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

Powering on a Droplet

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

Resizing a Droplet

/**
 * 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);

Reset a Droplet's password

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

Renaming a Droplet

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

Enable IPv6 for a Droplet

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

Enable Private Networking for a Droplet

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

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email owzie123@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.