- Can I use this bundle directly in Laravel, or is it strictly for Symfony?
- This bundle is designed for Symfony and API Platform, not Laravel. However, you can still use the underlying DigitalOceanPHP/Client library (via Composer) in Laravel by installing `digitalocean/v2` directly. The bundle’s Symfony-specific features—like autowiring and configuration—won’t apply, but the core API client will work.
- How do I authenticate with DigitalOcean’s API using this bundle?
- Authentication is handled via a DigitalOcean API token, which you configure in Symfony’s `config/packages/dunglas_digital_ocean.yaml`. The bundle injects the token into the `Client` service automatically, so no manual headers or credentials are needed in your code. Always use environment variables (`.env`) for tokens to avoid hardcoding.
- What Laravel versions does this bundle support?
- This bundle is **not** for Laravel—it’s for Symfony 7/8. However, if you’re using Laravel and need DigitalOcean API access, install the standalone `digitalocean/v2` client via Composer. For Laravel + Symfony interop, consider Laravel’s Symfony bridge or standalone HTTP clients like Guzzle.
- How do I handle pagination for large API responses (e.g., listing all droplets)?
- The bundle includes a `ResultPager` class to simplify pagination. Use `$pager->fetchAll($client->droplet(), 'getAll')` to fetch all results in chunks, avoiding memory issues. For Laravel, the standalone `digitalocean/v2` client also supports pagination via cursor-based or page-based methods.
- Is this bundle compatible with API Platform for exposing DigitalOcean resources as REST endpoints?
- Yes, the bundle is explicitly designed for API Platform. You can expose DigitalOcean resources (e.g., droplets, databases) as REST endpoints with minimal configuration. The bundle integrates with API Platform’s hydration/serialization system, making it easy to build internal developer portals or headless infrastructure APIs.
- How do I mock the DigitalOcean client for testing in Symfony?
- Use Symfony’s `MockHttpClient` to mock HTTP responses. Inject a mocked client into your services or controllers during tests. For example: `$mockClient = new MockHttpClient([new Response(200, [], json_encode(['droplets' => []]))]);` Then bind it in your test’s container or pass it directly to the service under test.
- What happens if DigitalOcean’s API rate limits me (e.g., 500 requests/minute)?
- The bundle relies on Symfony’s `HttpClient`, which supports retries and exponential backoff via middleware. Configure retries in your `config/packages/http_client.yaml` to handle rate limits gracefully. For high-volume operations, cache responses (e.g., with Symfony’s Cache component) or use multiple API tokens to distribute load.
- Can I use this bundle in a multi-cloud setup, or is it DigitalOcean-only?
- This bundle is DigitalOcean-specific and doesn’t abstract cloud provider differences. For multi-cloud, consider frameworks like Terraform or Pulumi, or build a wrapper layer around this bundle and similar clients (e.g., AWS SDK, Azure SDK). The bundle’s design allows you to extend it for custom logic if needed.
- How do I configure multiple DigitalOcean API tokens (e.g., for dev/staging/prod)?
- The bundle supports multiple clients via Symfony’s parameter system. Define tokens in `config/packages/dunglas_digital_ocean.yaml` under `clients:` with unique names (e.g., `prod`, `staging`). Inject the specific client service where needed (e.g., `$doClient->getClient('prod')`). Use environment variables for each token.
- Are there alternatives to this bundle for Laravel/DigitalOcean integration?
- For Laravel, the standalone `digitalocean/v2` client is the most direct alternative. For Symfony, this bundle is the most feature-rich option, offering tight integration with Symfony’s ecosystem. If you need a no-frills solution, Guzzle + raw API calls work but lack autowiring, pagination helpers, and API Platform support.