Symfony SDK
subdomainto/symfony-bundle supports Symfony 6.4, 7.4, and 8.x. It configures the PSR-18 client, autowiring, and webhook verification.
Installation
composer require subdomainto/symfony-bundle
Symfony Flex normally registers the bundle. Otherwise add SubdomainTo\Symfony\SubdomainToBundle::class => ['all' => true] to config/bundles.php.
Configuration
SUBDOMAINTO_API_KEY=sdt_live_xxxxxxxxxxxxxxxxxxxxxxxx
SUBDOMAINTO_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxx
# config/packages/subdomain_to.yaml
subdomain_to:
api_key: '%env(SUBDOMAINTO_API_KEY)%'
webhook_secret: '%env(SUBDOMAINTO_WEBHOOK_SECRET)%'
webhook_tolerance: 300
base_uri is optional and defaults to https://api.subdomain.to/v1.
Autowire the client
use SubdomainTo\Client;
final class CustomerDomainManager
{
public function __construct(private Client $subdomainTo) {}
public function connect(string $customerId, string $domain): string
{
return $this->subdomainTo->domains()->create($domain, $customerId.'-domain')->id();
}
}
The service is also available through the subdomain_to.client alias.
Verify a webhook controller
use SubdomainTo\Symfony\Attribute\VerifySubdomainToWebhook;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class SubdomainToWebhookController
{
#[Route('/webhooks/subdomainto', methods: ['POST'])]
#[VerifySubdomainToWebhook]
public function __invoke(Request $request): Response
{
$event = $request->attributes->get('subdomainto_event');
return new Response(status: 204);
}
}
The subscriber validates the signature and timestamp tolerance before invoking the controller. Invalid deliveries automatically receive 400. The attribute can receive a dedicated secret when needed.