common-gateway/zgw-vrijbrp-request-bundle
Install the Bundle Run via Composer:
composer require common-gateway/zgw-vrijbrp-request-bundle:dev-main
Or via Docker:
docker-compose exec php composer require common-gateway/zgw-vrijbrp-request-bundle:dev-main
Install Schemas Execute the console command to register the bundle’s schemas:
php bin/console commongateway:install common-gateway/zgw-vrijbrp-request-bundle
Verify Installation
ZgwVrijBRPRequestBundle and ensure it appears in the list.php bin/console commongateway:plugin:install zgw-vrijbrp-request-bundle
First Use Case: Sending a Request Use the bundle’s service to send a request to the VrijBRP API (e.g., fetching address data):
use CommonGateway\ZgwVrijBRPRequestBundle\Service\VrijBRPRequestService;
class MyController extends AbstractController
{
public function __construct(
private VrijBRPRequestService $vrijBRPRequestService
) {}
public function fetchAddress(Request $request): Response
{
$response = $this->vrijBRPRequestService->fetchAddress(
$request->query->get('addressId')
);
return $this->json($response);
}
}
config/routes.yaml:
my_address_route:
path: /api/address/{addressId}
controller: App\Controller\MyController::fetchAddress
Plugin-Based Request Handling
VrijBRPRequestService into controllers or command handlers.
$this->vrijBRPRequestService->fetchPerson($personId);
$this->vrijBRPRequestService->searchAddresses($criteria);
Schema-Driven Configuration
NelmioApiDocBundle.Validator).Event-Driven Extensions
zgw.vrijbrp.request.success) to intercept or modify responses:
// src/EventListener/VrijBRPResponseListener.php
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => ['onVrijBRPResponse', 100],
];
}
public function onVrijBRPResponse(ResponseEvent $event): void
{
$response = $event->getResponse();
if ($response->headers->contains('X-VrijBRP-Request')) {
// Transform or log the response
}
}
Command-Line Automation
php bin/console zgw:vrijbrp:sync --endpoint=addresses --limit=100
VrijBRPRequestService.Caching Responses Cache API responses to reduce calls to VrijBRP:
use Symfony\Contracts\Cache\CacheInterface;
$cache = $this->container->get('cache.app');
$cachedResponse = $cache->get("vrijbrp_address_{$addressId}", function() use ($addressId) {
return $this->vrijBRPRequestService->fetchAddress($addressId);
});
Error Handling
ZgwVrijBRPException:
try {
$data = $this->vrijBRPRequestService->fetchOrganization($orgId);
} catch (ZgwVrijBRPException $e) {
$this->addFlash('error', $e->getMessage());
return $this->redirectToRoute('home');
}
Testing
VrijBRPRequestService in tests:
$mockService = $this->createMock(VrijBRPRequestService::class);
$mockService->method('fetchAddress')
->willReturn(['id' => 123, 'street' => 'Test Street']);
$controller = new MyController($mockService);
HttpClient for integration tests to verify API responses.Custom Endpoints
VrijBRPRequestService:
class CustomVrijBRPService extends VrijBRPRequestService
{
public function fetchCustomData($endpoint, array $params): array
{
return $this->request('GET', $endpoint, $params);
}
}
services.yaml:
services:
App\Service\CustomVrijBRPService:
arguments:
$client: '@http_client'
tags: ['zgw.vrijbrp.service']
Schema Mismatches
commongateway:install or manually update schemas via the Admin UI.Authentication Issues
config/packages/zgw_vrijbrp.yaml.var/log/dev.log for ZgwVrijBRPException with auth-related messages.zgw_vrijbrp:
client_id: '%env(VIJBRP_CLIENT_ID)%'
client_secret: '%env(VIJBRP_CLIENT_SECRET)%'
Rate Limiting
use Symfony\Component\HttpClient\RetryableHttpException;
try {
$response = $this->client->request('GET', $url);
} catch (RetryableHttpException $e) {
sleep(2 ** $attempt); // Exponential backoff
retry();
}
Plugin Discovery Failures
composer.json includes the correct extra/commongateway metadata:
"extra": {
"commongateway": {
"name": "zgw-vrijbrp-request-bundle",
"title": "VrijBRP Request Plugin",
"description": "Extends Common Gateway with VrijBRP API requests."
}
}
Enable Verbose Logging
Add to config/packages/dev/zgw_vrijbrp.yaml:
zgw_vrijbrp:
debug: true
Logs will include request/response payloads in var/log/dev.log.
HTTP Client Debugging
Configure the HttpClient to log requests:
# config/packages/http_client.yaml
framework:
http_client:
plugins:
- Symfony\Bundle\HttpClientBundle\HttpClient\EventListener\ProfilerListener
View requests in the Profiler (/_profiler).
Common Exceptions
ZgwVrijBRPInvalidResponseException: The API returned an unexpected format.
ZgwVrijBRPAuthenticationException: Invalid credentials or token.
zgw_vrijbrp.yaml.ZgwVrijBRPRequestHandlerInterface:
class CustomRequestHandler implements ZgwVrijBRPRequestHandlerInterface
{
public function handle(Request $request): Response
{
// Custom logic (e.g., add headers, transform payload)
return $this->client->send($request);
How can I help you explore Laravel packages today?