tourze/digital-ocean-account-bundle

DigitalOcean账号信息管理包,提供账号同步、信息获取等功能

Installs: 220

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/digital-ocean-account-bundle

0.1.1 2025-05-28 07:06 UTC

This package is auto-updated.

Last update: 2025-11-13 17:57:17 UTC


README

PHP License Latest Version Build Status Total Downloads Code Coverage

A Symfony bundle for integrating with DigitalOcean API, providing account management, SSH key management, and configuration services.

English | 中文

Table of Contents

Features

  • DigitalOcean API v2 integration
  • Account information management and synchronization
  • Configuration management for DigitalOcean API access
  • Doctrine ORM integration for data persistence
  • Symfony Bundle integration with autowiring support

Dependencies

This bundle requires the following components:

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Doctrine ORM 3.0 or higher
  • HTTP Client Bundle for API communication

For a complete list of dependencies, please see the composer.json file.

Installation

Install the bundle via Composer:

composer require tourze/digital-ocean-account-bundle

Register the bundle in your config/bundles.php file:

<?php

return [
    // ...
    DigitalOceanAccountBundle\DigitalOceanAccountBundle::class => ['all' => true],
    // ...
];

Configuration

Database Setup

Run the following command to create the necessary database tables:

php bin/console doctrine:migrations:migrate

API Configuration

Create a DigitalOcean configuration record in your database with your API key:

// In a controller or service
$config = new DigitalOceanConfig();
$config->setApiKey('your-digitalocean-api-key');
$config->setRemark('Production API Key');

$this->entityManager->persist($config);
$this->entityManager->flush();

Bundle Configuration

The bundle automatically registers all services. No additional configuration is required for basic usage.

Quick Start

Usage Examples

Accessing Account Information

<?php

use DigitalOceanAccountBundle\Service\AccountService;

class YourController
{
    public function index(AccountService $accountService)
    {
        // Get account information from DigitalOcean API
        $accountData = $accountService->getAccount();
        
        // Synchronize account information to database
        $account = $accountService->syncAccount();
        
        // Use account data...
    }
}

Managing Configuration

<?php

use DigitalOceanAccountBundle\Service\DigitalOceanConfigService;

class ConfigController
{
    public function setup(DigitalOceanConfigService $configService)
    {
        // Get the current configuration
        $config = $configService->getConfig();
        
        // The service will automatically use the configured API key
        // for all DigitalOcean API requests
    }
}

API Documentation

The bundle provides several services for interacting with the DigitalOcean API:

AccountService

  • getAccount(): Retrieve account information from DigitalOcean API
  • syncAccount(): Synchronize account information to database

DigitalOceanConfigService

  • getConfig(): Get the current DigitalOcean API configuration

DigitalOceanClient

  • request(DigitalOceanRequest $request): Send requests to DigitalOcean API

Each service is automatically registered and can be autowired in your Symfony application.

Advanced Usage

Custom Request Types

You can create custom request types by extending the DigitalOceanRequest class:

<?php

use DigitalOceanAccountBundle\Request\DigitalOceanRequest;

class CustomRequest extends DigitalOceanRequest
{
    protected function getEndpoint(): string
    {
        return '/v2/custom-endpoint';
    }
    
    protected function getMethod(): string
    {
        return 'GET';
    }
}

Error Handling

The bundle provides custom exceptions for different error scenarios:

<?php

use DigitalOceanAccountBundle\Exception\DigitalOceanException;
use DigitalOceanAccountBundle\Exception\MissingApiKeyException;

try {
    $account = $accountService->syncAccount();
} catch (MissingApiKeyException $e) {
    // Handle missing API key
} catch (DigitalOceanException $e) {
    // Handle other DigitalOcean-related errors
}

Testing

The bundle includes comprehensive test coverage. Run tests with:

vendor/bin/phpunit packages/digital-ocean-account-bundle/tests

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for your changes
  5. Submit a pull request

License

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