php-parallel-lint/php-console-highlighter
Highlight PHP source code in the terminal with readable, colorized syntax. php-console-highlighter works with ConsoleColor and can highlight whole files or snippets—ideal for CLI tools, linters, and test output to quickly spot errors and context.
This package provides terminal syntax highlighting for PHP code—primarily useful for CLI tools and output formatting. Start by requiring it via Composer:
composer require php-parallel-lint/php-console-highlighter
Usage is minimal: instantiate PHP_Parallel_Lint\ConsoleHighlighter, then call highlight() with PHP source code. It integrates directly with STDOUT (or any stream) for colored output. A common first use case is enhancing CLI tool output (e.g., in artisan commands, custom linting scripts, or IDE integrations) to make PHP snippets easier to read.
Note: As of v1.0.0, the namespace has changed from
JakubOnderka\ConsoleHighlightertoPHP_Parallel_Lint\ConsoleHighlighter. Update imports accordingly.
STDOUT) to the constructor for immediate colored rendering:
use PHP_Parallel_Lint\ConsoleHighlighter;
$highlighter = new ConsoleHighlighter(STDOUT);
$highlighter->highlight("<?php echo 'Hello';");
highlightString() to capture highlighted code as an ANSI-formatted string (e.g., for logging or embedding in multi-step CLI output):
$output = $highlighter->highlightString($code);
fwrite(STDERR, $output);
Command class, inject or instantiate the highlighter and use it inside handle() to output structured PHP snippets (e.g., showing generated boilerplate, scaffolding templates, or config diffs) with clear syntax cues. Ensure your command checks for ANSI support ($this->output->isVerbose() or OutputInterface::OUTPUT_RAW).php-parallel-lint/parallel-lint—highlight diffs or problematic code blocks after linting failures.PHP_Parallel_Lint (not JakubOnderka). Replace use JakubOnderka\ConsoleHighlighter; with use PHP_Parallel_Lint\ConsoleHighlighter; to avoid fatal errors.symfony/polyfill-ansi or enabling Windows 10 virtual terminal support. Check !_windows() or wrap with stream_isatty(STDOUT).readonly properties, match expressions) and restores PHP 5.3 compatibility—making syntax handling more robust across legacy and modern code.NO_COLOR environment variable or --no-ansi flag in Laravel by checking OutputInterface::isVerbose() or environment state before highlighting.Lexer class if needed for internal tooling.php-console-color ^1.0.1, improving cross-platform color handling and reducing edge-case rendering issues.How can I help you explore Laravel packages today?