league/climate
League CLImate makes PHP CLI output nicer with easy colored text, formatting, and styled messages. Install via Composer and use simple methods like red() or blue() to print readable, attention-grabbing console output for scripts and command-line tools.
artisan commands, migrations, and custom console tools). It replaces ad-hoc echo/error_log calls with a consistent, object-oriented API, aligning with Laravel’s design principles.$climate->success()->bold('Done!')) and custom output writers, enabling Laravel to extend it for domain-specific needs (e.g., custom progress bars for migrations).Log::channel('climate')), ensuring consistency with existing logging systems.composer require league/climate) and initialization (new \League\CLImate\CLImate) are trivial.Console/Kernel or individual commands via service container binding:
$this->app->singleton(\League\CLImate\CLImate::class, function () {
return new \League\CLImate\CLImate;
});
echo statements in CLImate methods (e.g., replace echo "Error!" with $climate->error('Error!')).forceAnsiOff()).echo usage via static analysis tools (e.g., PHPStan rules).migrationProgress()) or keep it generic?echo be allowed for critical paths?confirm(), checkboxes()) for all interactive CLI tools, or allow alternatives?echo/error_log with CLImate methods (e.g., $this->climate->info('Command started')).$climate->progress()->start('Migrating...')).php artisan db:backup).stdout.Log::channel('stack')->debug() with $climate->logger()->debug() for CLI-specific logs.$climate->error('Database connection failed')).readline() with CLImate’s interactive prompts (e.g., $climate->confirm('Overwrite file?')).| Phase | Action | Example |
|---|---|---|
| Assessment | Audit existing CLI tools for echo/error_log usage. |
grep -r "echo " app/Console" > legacy_cli_usage.txt |
| Pilot | Adopt CLImate in non-critical tools (e.g., debug commands). | Replace echo "User created: $user" with $climate->success("User created: $user") |
| Core Adoption | Mandate CLImate for new CLI tools and high-impact commands. | Add use League\CLImate\CLImate; to app/Console/Kernel.php |
| Refactor | Gradually replace legacy output in critical paths (e.g., migrations). | Wrap echo "Running migrations..." in $climate->section('Migrations') |
| Deprecation | Deprecate raw echo in CLI tools via PHPStan rules. |
Add disallow_echo_in_cli rule to phpstan.neon |
symfony/console).ext-mbstring for multibyte support (CLImate suggests symfony/polyfill-mbstring if missing).$climate->forceAnsiOff()).Phase 1: Core Integration (2 weeks)
CLICommand trait for consistent output:
trait UsesCLImate {
protected $climate;
public function __construct(CLImate $climate) { $this->climate = $climate; }
}
$climate->table(), $climate->progress()).Phase 2: Pilot Programs (4 weeks)
php artisan tinker, debug commands).Phase 3: Critical Paths (6 weeks)
Phase 4: Enforcement (Ongoing)
echo in CLI tools via static analysis.league/climate) to update, rather than patching individual CLI tools.echo patterns.How can I help you explore Laravel packages today?