Download the PHP package jeffersongoncalves/laravel-zero-console without Composer
On this page you can find all versions of the php package jeffersongoncalves/laravel-zero-console. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeffersongoncalves/laravel-zero-console
More information about jeffersongoncalves/laravel-zero-console
Files in jeffersongoncalves/laravel-zero-console
Package laravel-zero-console
Short Description Reusable traits for Laravel Zero commands: output formatting (tables, state colorization, dates), standardized API error handling, and cwd/argument path resolution.
License MIT
Homepage https://github.com/jeffersongoncalves/laravel-zero-console
Informations about the package laravel-zero-console
laravel-zero-console
Reusable traits for Laravel Zero (and plain Laravel) commands. Extracted from real CLIs that kept copy-pasting the same helpers: output formatting, standardized API error handling, and path resolution.
Why
Every CLI ends up reimplementing the same chores: rendering tables that gracefully
handle empty results, colorizing status strings, formatting dates, swallowing API
exceptions into clean exit codes, and turning a path argument (or the cwd) into a
real filesystem path. This package ships those as small, focused traits.
Installation
Requires PHP ^8.2 and illuminate/console ^11.0|^12.0.
Traits
FormatsOutput
Use inside an Illuminate\Console\Command (relies on $this->table() and
$this->components).
Methods:
renderTable(array $headers, array $rows): void— renders a table, or an info message when there are no rows.colorize(string $value, string $color): string— wraps a value in<fg=color>...</>tags.stateColor(string $state): string— case-insensitive lookup of a console color for a state.stateColors(): array— the state→color map. Override it to customize. The default merges pull-request states (OPEN,MERGED,DECLINED,SUPERSEDED) with issue-tracker states (TODO,IN PROGRESS,DONE).formatDate(?string $date, string $format = 'Y-m-d H:i'): string— formats a date string viaDateTime; returns-for null/empty/invalid input.
Customizing the color map:
HandlesApiErrors
handleApiErrors(callable $callback): int— runs the callback; on success returns its int result (orSUCCESSwhen it returns null); on anyThrowableprints the message via$this->components->error()and returnsFAILURE.
ResolvesPath
resolvePath(?string $argument = null): string— resolves an optional argument to its realpath, falling back to the cwd; returns the original input when the path does not exist.resolveCwd(): string— the current working directory resolved to its realpath.
Testing
License
MIT