DigitalOcean API v2 client for PHP
We present a modern DigitalOcean API v2 client for PHP.
Check out the change log, releases, security policy, license, code of conduct, and contribution guidelines.
This version supports PHP 8.1-8.5. To get started, simply require the project using Composer. You will also need to install packages that "provide" psr/http-client-implementation and psr/http-factory-implementation.
$ composer require "toin0u/digitalocean-v2:^5.1" "guzzlehttp/guzzle:^7.9.2"$ composer require "graham-campbell/digitalocean:^11.1"We are decoupled from any HTTP messaging client by using PSR-7, PSR-17, PSR-18, and HTTPlug. You can visit HTTPlug for library users to get more information about installing HTTPlug related packages. The framework integration graham-campbell/digitalocean is by Graham Campbell and dunglas/digital-ocean-bundle is by Kévin Dunglas.
If you are upgrading from version 2.3 to 3.0, or from 3.3 to 4.0, you can check out our upgrading guide. We highly recommend upgrading as soon as possible.
As of version 3.0, we will automatically discover an HTTP client to use, from what you have available. Simply create a new DigitalOcean client, provide your access token, then you're good to go:
authenticate('your_access_token');Version 3.0 also has a built-in paginator, and can be used on any of the APIs which return collections. By default, the pager will internally attempt to fetch 100 entries in each request, however this can be configured by passing a 2nd parameter to the constructor. We have included an example below which will fetch all droplets:
// create a new result pager
$pager = new DigitalOceanV2\ResultPager($client);
// get all droplets as an array
$droplets = $pager->fetchAll($client->droplet(), 'getAll');
// get all droplets as a Generator which lazily yields
// new results as they become available
$droplets = $pager->fetchAllLazy($client->droplet(), 'getAll');// return the account api
$account = $client->account();
// return the Account entity
$userInformation = $account->getUserInformation();// return the action api
$action = $client->action();
// return a collection of Action entity
$actions = $action->getAll();
// return the Action entity 123
$action123 = $action->getById(123);………// return the domain api
$domain = $client->domain();
// return a collection of Domain entity
$domains = $domain->getAll();
// return the Domain entity 'foo.dk'
$domainFooDk = $domain->getByName('foo.dk');
// return the created Domain named 'bar.dk' and pointed to ip '127.0.0.1'
$created = $domain->create('bar.dk', '127.0.0.1');
// remove the domain named 'baz.dk'
$domain->remove('baz.dk');……………………// return the region api
$region = $client->region();
// return a collection of Region entity
$regions = $region->getAll();// return the size api
$size = $client->size();
// return a collection of Size entity
$sizes = $size->getAll();// return the tag api
$tag = $client->tag();
// return a collection of Tag entity
$tags = $tag->getAll();
// return a Tag entity by name
$tagEntity = $tag->getByName('awesome');
// create a tag
$createdTag = $tag->create('awesome');
// tag resources
$tag->tagResources('awesome', [["resource_id" => "9569411", "resource_type" => "droplet"]]);
// untag resources
$tag->untagResources('awesome', [["resource_id" => "9569411", "resource_type" => "droplet"]]);
// remove tag
$tag->remove('awesome');…// return the VPC api
$vpc = $client->vpc();
// returns all VPCs
$vpcs = $vpc->getAll();We will gladly receive issue reports and review and accept pull requests, in accordance with our code of conduct and contribution guidelines!
$ make install
$ make testIf you discover a security vulnerability within this package, please send an email to [email protected]. All security vulnerabilities will be promptly addressed. You may view our full security policy here.
DigitalOcean PHP API Client is licensed under The MIT License (MIT).
No open issues yet, or sync has not completed.