Install via Composer
composer require common-gateway/brk-bundle
Ensure your composer.json includes Symfony 5+ and PHP 7.4+.
Enable the Bundle
Add to config/bundles.php:
return [
// ...
CommonGateway\BrkBundle\BrkBundle::class => ['all' => true],
];
Configure API Credentials Publish the default config:
php bin/console brk:install
Update config/packages/brk.yaml with your Kadaster API credentials (e.g., client_id, client_secret).
First API Call Use the service in a controller:
use CommonGateway\BrkBundle\Service\BrkApiService;
class BrkController extends AbstractController {
public function __construct(private BrkApiService $brkApi) {}
public function searchParcel(string $brkNumber): Response {
$data = $this->brkApi->getParcelData($brkNumber);
return $this->json($data);
}
}
Test Locally Use the built-in CLI command to verify connectivity:
php bin/console brk:test-connection
Leverage the BrkApiService for structured queries:
// Get basic parcel info
$parcel = $this->brkApi->getParcel($brkNumber);
// Get historical transactions
$transactions = $this->brkApi->getParcelTransactions($brkNumber, new DateTime('2020-01-01'));
Use the BrkBatchService for bulk operations (e.g., syncing multiple parcels):
$batchService = $this->container->get(BrkBatchService::class);
$batchService->processBrkNumbers(['BRK123', 'BRK456'], function ($data) {
// Handle each parcel response
});
Subscribe to BRK events (e.g., BrkParcelUpdatedEvent) via Symfony’s event dispatcher:
// In a service constructor
public function __construct(private EventDispatcherInterface $dispatcher) {
$this->dispatcher->addListener(
BrkParcelUpdatedEvent::class,
[$this, 'handleParcelUpdate']
);
}
public function handleParcelUpdate(BrkParcelUpdatedEvent $event) {
// Log or process updated data
}
Enable caching for frequent queries via BrkCacheService:
# config/packages/brk.yaml
brk:
cache_enabled: true
cache_ttl: 3600 # 1 hour
BrkType form type for BRK number validation:
use CommonGateway\BrkBundle\Form\Type\BrkType;
$builder->add('brkNumber', BrkType::class);
BrkApiService for throttled requests:
$this->brkApi->setRetryPolicy(new ExponentialBackoffRetryPolicy());
BrkHydrator:
$hydrator = new BrkHydrator();
$parcelEntity = $hydrator->hydrate($brkResponse, new Parcel());
API Rate Limits
BrkApiService or use the built-in BrkRateLimiter.Deprecated Endpoints
brk.log file for 404 or 410 errors and update the bundle’s BrkClient configuration.Sensitive Data Exposure
brk.yaml risks leaks.parameter_bag or environment variables:
brk:
client_id: "%env(BRK_CLIENT_ID)%"
Time Zone Mismatches
BrkDateConverter:
$localDate = $this->brkDateConverter->toLocalTime($utcTimestamp);
Enable Verbose Logging
Set debug: true in brk.yaml to log raw API responses:
brk:
debug: true
Logs appear in var/log/brk.log.
Mock the API for Testing
Use the BrkMockClient in tests:
$this->container->set(BrkClientInterface::class, new BrkMockClient());
Custom Hydrators
Extend BrkHydrator to map BRK responses to your domain models:
class CustomBrkHydrator extends BrkHydrator {
protected function hydrateParcel(array $data): Parcel {
$parcel = parent::hydrateParcel($data);
$parcel->setCustomField($data['custom_field']);
return $parcel;
}
}
Event Listeners
Add listeners for BrkEvent types (e.g., BrkParcelFetchedEvent) to intercept or modify data:
$dispatcher->addListener(BrkParcelFetchedEvent::class, function ($event) {
$event->setData($this->transformData($event->getData()));
});
Custom API Clients
Replace BrkClient with a custom implementation (e.g., for GraphQL):
$this->container->set(BrkClientInterface::class, new CustomBrkGraphqlClient());
php bin/console cache:clear BRK_CACHE
%kernel.environment% to load different API endpoints per environment:
brk:
api_url: "%brk.api_url_%"
Define in .env:
BRK_API_URL="https://api.kadaster.nl/prod" # prod
BRK_API_URL="https://api.kadaster.nl/test" # test
How can I help you explore Laravel packages today?