dbp/relay-greenlight-bundle
Installation
composer require dbp/relay-greenlight-bundle
Add the bundle to config/bundles.php:
return [
// ...
DigitalBlueprint\RelayGreenlightBundle\RelayGreenlightBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console dbp:relay-greenlight:install
Update config/packages/dbp_relay_greenlight.yaml with your DCC (Digital COVID Certificate) relay server credentials (if available).
First Use Case Generate a test permit via CLI:
php bin/console dbp:relay-greenlight:generate-permit
Verify the output in var/log/relay_greenlight.log.
Permit Generation
Use the PermitGenerator service to create permits programmatically:
$generator = $this->container->get('dbp_relay_greenlight.permit_generator');
$permit = $generator->generate([
'subject' => 'Test User',
'issuer' => 'Test Issuer',
'valid_from' => now()->subDays(1),
'valid_until' => now()->addDays(1),
]);
Event-Driven Permits Extend the bundle to trigger permit generation on events (e.g., user registration):
// In a listener
public function onUserRegistered(UserRegisteredEvent $event) {
$generator = $this->container->get('dbp_relay_greenlight.permit_generator');
$generator->generateForUser($event->getUser());
}
Validation Integration Validate permits in controllers/middleware:
use DigitalBlueprint\RelayGreenlightBundle\Validator\PermitValidator;
$validator = new PermitValidator();
if (!$validator->isValid($permitData)) {
throw new \RuntimeException('Invalid permit');
}
PermitGenerator and PermitValidator.Permit entity to store permits in the database:
$entityManager->persist($permit);
$entityManager->flush();
#[Route('/api/permit', methods: ['POST'])]
public function generatePermit(Request $request, PermitGenerator $generator) {
$data = json_decode($request->getContent(), true);
return new JsonResponse($generator->generate($data));
}
Deprecated Infrastructure
Configuration Overrides
config/packages/dbp_relay_greenlight.yaml:
dbp_relay_greenlight:
relay_server_url: 'http://localhost:8080' # Mock URL
timeout: 30
Logging Dependencies
monolog is configured in config/packages/monolog.yaml:
handlers:
main:
type: stream
path: '%kernel.logs_dir%/relay_greenlight.log'
level: debug
Mocking the Relay Server
Use PHPUnit to mock the RelayClient service:
$mockClient = $this->createMock(RelayClient::class);
$mockClient->method('requestPermit')->willReturn(['mock' => 'response']);
$this->container->set('dbp_relay_greenlight.relay_client', $mockClient);
Validation Errors Enable debug mode to see detailed validation errors:
$validator = new PermitValidator();
$errors = $validator->validate($permitData);
dd($errors); // Debug validation issues
Custom Permit Fields
Extend the Permit entity:
namespace App\Entity;
use DigitalBlueprint\RelayGreenlightBundle\Entity\Permit as BasePermit;
class Permit extends BasePermit {
#[ORM\Column(type: 'string', nullable: true)]
private ?string $customField = null;
// Add getters/setters
}
Event Listeners
Subscribe to the PermitGeneratedEvent:
#[AsEventListener(event: PermitGeneratedEvent::class)]
public function onPermitGenerated(PermitGeneratedEvent $event) {
// Send email, log, etc.
}
Override Templates
Customize the permit template by copying templates/permit.html.twig to templates/dbprelaygreenlight/permit.html.twig.
$cache = $this->container->get('cache.app');
$permit = $cache->get('permit_' . $userId) ?: $generator->generateForUser($user);
How can I help you explore Laravel packages today?