Giter VIP home page Giter VIP logo

dunglasdigitaloceanbundle's Introduction

DigitalOcean Bundle for Symfony and API Platform

DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projects. It registers the DigitalOcean PHP API Client as a Symfony service.

If you aren't yet a DigitalOcean user, use this affiliate link to get $100 in free credit!

If you want to deploy your Symfony apps to DigitalOcean, checkout this tutorial.

Example

// src/Controller/DigitalOceanController.php
namespace App\Controller;

use DigitalOceanV2\Client;
use DigitalOceanV2\ResultPager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ProductController
{
    #[Route("/droplets")]
    public function listDroplets(Client $doClient): Response
    {
        // get the first 100 droplets as an array
        $droplets = $doClient->droplet()->getAll();
        
        // or create a new result pager
        $pager = new ResultPager($doClient);

        // and get all droplets as an array
        $droplets = $pager->fetchAll($doClient->droplet(), 'getAll'); 

        // ...
    }
}

Of course, you can also inject the client service into your commands, messenger handlers and any other service.

More examples.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require dunglas/digital-ocean-bundle symfony/http-client nyholm/psr7 guzzlehttp/promises

The previous command installs the bundle, Symfony HttpClient and the dependencies it needs to "provide" psr/http-client-implementation and psr/http-factory-implementation.

Alternatively, you can use any other implementation of these interfaces such as Guzzle.

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require dunglas/digital-ocean-bundle symfony/http-client nyholm/psr7 guzzlehttp/promises

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    \Dunglas\DigitalOceanBundle\DunglasDigitalOceanBundle::class => ['all' => true],
];

Configuration

dunglas_digital_ocean:
    connections:
        primary: # can be any name
            token: <your-access-token>
        secondary:
            token: <your-access-token>
    default_connection: primary # If not set, the first in the list will be used

This configuration automatically registers the following autowiring aliases:

DigitalOceanV2\Client $primaryClient
DigitalOceanV2\Client $secondaryClient

If you have only one client, you can use this shortcut:

dunglas_digital_ocean: <your-access-token>

Use the DigitalOceanV2\Client type to inject the default DigitalOcean client.

Credits

This bundle is brought to you by Kévin Dunglas. It is sponsored by Les-Tilleuls.coop.

dunglasdigitaloceanbundle's People

Contributors

dunglas avatar tarlepp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.