PHP code example of toin0u / digitalocean-silex

1. Go to this page and download the library: Download toin0u/digitalocean-silex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toin0u / digitalocean-silex example snippets




use DigitalOcean\Silex\DigitalOceanServiceProvider;

// .. create $app
$app->register(new DigitalOceanServiceProvider(), array(
    'digitalocean.client_id' => 'YOUR_CLIENT_ID',
    'digitalocean.api_key'   => 'YOUR_API_KEY',
));

$digitalOcean = $app['digitalocean'];
$digitalocean->setAdapter(new \HttpAdapter\BuzzHttpAdapter());
$activeDroplets = $digitalOcean->droplets()->showAllActive();
var_dump($activeDroplets);

// object(stdClass)[61]
// public 'status' => string 'OK' (length=2)
// public 'droplets' =>
//     array (size=1)
//         0 =>
//             object(stdClass)[62]
//                 public 'id' => int 347553
//                 public 'name' => string 'foobar' (length=6)
//                 public 'image_id' => int 284212
//                 public 'size_id' => int 66
//                 public 'region_id' => int 4
//                 public 'backups_active' => boolean false
//                 public 'ip_address' => string '192.241.175.217' (length=15)
//                 public 'private_ip_address' => null
//                 public 'locked' => boolean false
//                 public 'status' => string 'active' (length=6)
//                 public 'created_at' => string '2013-01-07T01:37:21Z' (length=20)
bash
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install