'Simple Text',
'data' => 'Hello, World!',
'description' => 'Basic text QR code (Version 1)',
'version' => null,
'errorLevel' => null,
],
[
'title' => 'URL Example',
'data' => 'https://example.com/test?param=value',
'description' => 'Website URL QR code',
'version' => null,
'errorLevel' => ErrorCorrectionLevel::M,
],
[
'title' => 'TOTP Example',
'data' => 'otpauth://totp/TestApp:user@example.com?secret=JBSWY3DPEHPK3PXP&issuer=TestApp&algorithm=SHA1&digits=6&period=30',
'description' => 'TOTP authenticator setup (Version 3)',
'version' => QrCodeVersion::forTotp(),
'errorLevel' => ErrorCorrectionLevel::M,
],
[
'title' => 'WiFi Connection',
'data' => 'WIFI:T:WPA;S:TestNetwork;P:password123;H:false;;',
'description' => 'WiFi connection QR code',
'version' => null,
'errorLevel' => ErrorCorrectionLevel::L,
],
[
'title' => 'Contact Card',
'data' => 'BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL:+49123456789\nEMAIL:john@example.com\nEND:VCARD',
'description' => 'vCard contact information',
'version' => null,
'errorLevel' => ErrorCorrectionLevel::M,
],
];
$qrCodes = [];
foreach ($examples as $example) {
try {
// Generate SVG
$svg = $this->qrCodeGenerator->generateSvg(
$example['data'],
$example['errorLevel'],
$example['version']
);
// Generate data URI
$dataUri = $this->qrCodeGenerator->generateDataUri(
$example['data'],
$example['errorLevel'],
$example['version']
);
// Analyze the data
$analysis = $this->qrCodeGenerator->analyzeData($example['data']);
$qrCodes[] = [
'title' => $example['title'],
'description' => $example['description'],
'data' => $example['data'],
'svg' => $svg,
'dataUri' => $dataUri,
'analysis' => $analysis,
'success' => true,
];
} catch (\Exception $e) {
$qrCodes[] = [
'title' => $example['title'],
'description' => $example['description'],
'data' => $example['data'],
'error' => $e->getMessage(),
'success' => false,
];
}
}
$html = $this->generateTestPageHtml($qrCodes);
return new HtmlResult($html);
}
/**
* Generate individual QR code for API testing
*/
#[Route(path: '/test/qr-code', method: Method::GET)]
public function generateTestQrCode(HttpRequest $request): HtmlResult|HttpResponse
{
$data = (string) $request->query->get('data', 'Test QR Code from API');
$format = $request->query->get('format', 'svg'); // svg or datauri
$errorLevel = $request->query->get('error', 'M');
$version = $request->query->get('version');
try {
// Parse error correction level
$errorCorrectionLevel = match($errorLevel) {
'L' => ErrorCorrectionLevel::L,
'Q' => ErrorCorrectionLevel::Q,
'H' => ErrorCorrectionLevel::H,
default => ErrorCorrectionLevel::M,
};
// Parse version if provided
$qrVersion = $version ? new QrCodeVersion((int) $version) : null;
if ($format === 'datauri') {
$result = $this->qrCodeGenerator->generateDataUri($data, $errorCorrectionLevel, $qrVersion);
return new HtmlResult("");
} else {
$svg = $this->qrCodeGenerator->generateSvg($data, $errorCorrectionLevel, $qrVersion);
return new HttpResponse(
Status::OK,
new Headers(['Content-Type' => 'image/svg+xml']),
$svg
);
}
} catch (\Exception $e) {
return new HtmlResult(
"
{$e->getMessage()}
", Status::INTERNAL_SERVER_ERROR ); } } /** * Generate test page HTML * @param array{$qrCode['description']}
" . htmlspecialchars($qrCode['data']) . "
{$qrCode['description']}
" . htmlspecialchars($qrCode['data']) . "
Dynamic QR Code Generation:
GET /test/qr-code?data=Your+Data&format=svg&error=M&version=3
Parameters:
data - Text to encode (URL encoded)format - Output format: svg (default) or dataurierror - Error correction: L, M (default), Q, Hversion - QR version 1-40 (auto-detect if omitted)Examples:
/test/qr-code?data=Hello+World
/test/qr-code?data=https://example.com&error=H
/test/qr-code?data=Test&format=datauri&version=2
โ QR Code Framework Module - Fully Functional
Generated by Custom PHP Framework QR Code Generator