Files
michaelschiemer/test_modern_syntax_highlighter.php
Michael Schiemer 55a330b223 Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
2025-08-11 20:13:26 +02:00

72 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';
use App\Framework\SyntaxHighlighter\SyntaxHighlighter;
// Test code to highlight
$phpCode = <<<'PHP'
<?php
declare(strict_types=1);
namespace App\Example;
use App\Framework\Http\JsonResult;
#[Route(path: '/api/users', method: 'GET')]
final readonly class UserController
{
/**
* Get all users
*
* @param UserRepository $repository
* @return JsonResult<array<User>>
*/
public function getUsers(UserRepository $repository): JsonResult
{
$users = $repository->findAll();
$count = count($users);
return new JsonResult([
'users' => $users,
'count' => $count,
'message' => "Found {$count} users"
]);
}
}
PHP;
$highlighter = new SyntaxHighlighter();
// Test HTML output
echo "=== HTML Output ===\n";
$html = $highlighter->highlightWithCss($phpCode, [
'theme' => 'dark',
'lineNumbers' => true
]);
echo $html . "\n\n";
// Test console output
echo "=== Console Output ===\n";
$console = $highlighter->highlight($phpCode, 'console', [
'colorize' => true,
'lineNumbers' => true
]);
echo $console . "\n";
// Test tokenization
echo "=== Tokenization Test ===\n";
$tokens = $highlighter->tokenize($phpCode);
echo "Total tokens: " . $tokens->count() . "\n";
// Show first few tokens
$first5 = $tokens->slice(0, 5);
foreach ($first5 as $token) {
echo sprintf(
"Line %d: %s = '%s'\n",
$token->line,
$token->type->value,
trim($token->value)
);
}