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
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-client-contracts: ^2.5 | ^3.0
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/arrayable: 0.0.*
- tourze/bundle-dependency: 0.0.*
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/http-client-bundle: 0.1.*
- tourze/symfony-aop-doctrine-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-11-13 17:57:17 UTC
README
A Symfony bundle for integrating with DigitalOcean API, providing account management, SSH key management, and configuration services.
Table of Contents
- Features
- Dependencies
- Installation
- Configuration
- Quick Start
- API Documentation
- Advanced Usage
- Contributing
- License
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 APIsyncAccount(): 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.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for your changes
- Submit a pull request
License
The MIT License (MIT). Please see License File for more information.