'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("\"QR"); } 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( "

QR Code Generation Error

{$e->getMessage()}

", Status::INTERNAL_SERVER_ERROR ); } } /** * Generate test page HTML * @param array> $qrCodes */ private function generateTestPageHtml(array $qrCodes): string { $examples = ''; foreach ($qrCodes as $qrCode) { if ($qrCode['success']) { $analysis = $qrCode['analysis']; $analysisHtml = ''; foreach ($analysis as $key => $value) { $displayValue = is_object($value) ? basename(str_replace('\\', '/', get_class($value))) : $value; $analysisHtml .= "{$key}{$displayValue}"; } $examples .= "

{$qrCode['title']}

{$qrCode['description']}

\"{$qrCode['title']}

Data:

" . htmlspecialchars($qrCode['data']) . "

Analysis:

{$analysisHtml}
"; } else { $examples .= "

{$qrCode['title']} - ERROR

{$qrCode['description']}

Error: {$qrCode['error']}

" . htmlspecialchars($qrCode['data']) . "
"; } } return " QR Code Test Page

๐Ÿงช QR Code Test Page

๐Ÿ“ก API Endpoints

Dynamic QR Code Generation:
GET /test/qr-code?data=Your+Data&format=svg&error=M&version=3

Parameters:

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

{$examples}

โœ… QR Code Framework Module - Fully Functional

Generated by Custom PHP Framework QR Code Generator

"; } }