Install the Bundle
composer require aldaflux/ovh-bundle
Ensure your project uses Symfony 7.1+ (per composer.json).
Configure Credentials
Add OVH API keys to .env:
OVH_APPLICATION_KEY=your_app_key
OVH_APPLICATION_SECRET=your_app_secret
OVH_CONSUMER_KEY=your_consumer_key
Update config/packages/aldaflux_ovh.yaml with the required endpoint (e.g., "ovh-eu").
First Use Case: Fetching VPS Info
Inject the OvhClient service (auto-registered by the bundle) and call an API method:
use AldaFlux\OvhBundle\Service\OvhClient;
public function getVpsInfo(OvhClient $ovhClient)
{
$vps = $ovhClient->get('/vps', ['serviceName' => 'your_vps_service_name']);
return json_decode($vps->getBody(), true);
}
API Calls with Authentication
The bundle wraps the ovh/ovh library, so leverage its methods:
$ovhClient->post('/vps/boot', ['serviceName' => 'vps123']);
$ovhClient->delete('/domain/zone/example.com/record', ['subDomain' => 'www']);
Handling Responses
Use the OvhResponse object to access data:
$response = $ovhClient->get('/domain/zone/example.com/record');
if ($response->isSuccess()) {
$records = json_decode($response->getBody(), true);
} else {
throw new \RuntimeException($response->getErrorMessage());
}
Default Configuration
Use the optional default config (e.g., ip, domain) to avoid repeating values:
aldaflux_ovh:
default:
domain: '%env(resolve:DEFAULT_DOMAIN)%'
Access via:
$ovhClient->get('/domain/zone', ['domain' => $ovhClient->getConfig('domain')]);
Service Integration
Bind the OvhClient to a service in your controller/repo:
public function __construct(private OvhClient $ovhClient) {}
Ovh\Exception\OvhException).$this->logger->debug('OVH Response', ['body' => $response->getBody()]);
Endpoint Mismatch
ovh-eu vs. ovh-us) will fail silently or return incorrect data.aldaflux_ovh.yaml matches your OVH region.Missing Environment Variables
.env variables (e.g., OVH_APPLICATION_KEY) will throw ParameterNotFoundException..env with:
php bin/console debug:config aldaflux_ovh
Deprecated OVH API Methods
ovh/ovh library may not support newer OVH API v3 endpoints.Caching Responses
$cache = $this->container->get('cache.app');
$cached = $cache->get('ovh_dns_records', function() use ($ovhClient) {
return $ovhClient->get('/domain/zone/example.com/record')->getBody();
});
OVH_DEBUG=true in .env to log raw API requests/responses.dd($response->getHeaders()) to inspect HTTP headers for errors (e.g., X-Ovh-Api-Auth-Failure).Custom Services
Extend the bundle by creating a service that wraps OvhClient:
# config/services.yaml
services:
App\Service\OvhDnsManager:
arguments:
$ovhClient: '@aldaflux_ovh.client'
Event Listeners Listen for OVH API events (e.g., after a DNS update):
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(event: 'aldaflux_ovh.api.response', method: 'onOvhResponse')]
public function onOvhResponse(OvhResponseEvent $event) {
if ($event->getResponse()->getPath() === '/domain/zone/...') {
// Handle DNS update
}
}
Testing
Mock the OvhClient in tests:
$mockClient = $this->createMock(OvhClient::class);
$mockClient->method('get')->willReturn(new OvhResponse(200, '{"status":"ok"}'));
$this->container->set('aldaflux_ovh.client', $mockClient);
How can I help you explore Laravel packages today?