Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Output Formatters Laravel Package

consolidation/output-formatters

Flexible output formatting utilities for PHP/Laravel CLI apps. Convert structured data to clean tables, JSON, YAML, and more with consistent styling and easy configuration—ideal for Symfony Console/Drush-style commands needing polished, readable output.

View on GitHub
Deep Wiki
Context7

Getting Started

Begin by installing via Composer: composer require consolidation/output-formatters. The core use case is transforming PHP arrays or objects into formatted CLI output (e.g., tables, JSON). Start with FormatterManager, register default formatters (e.g., table, json, csv), then call format($data, $format, $options). For example:

$manager = new FormatterManager();
$manager->addFormatter(new TableFormatter());
$data = [['name' => 'Alice', 'role' => 'Admin']];
echo $manager->format($data, 'table');

The /docs folder (if present in the repo) or FormatterManager source is the best first reference.

Implementation Patterns

  • Inject FormatterManager into Symfony Console or Robo commands; set format dynamically via --format= option (e.g., --format=json), and apply transforms via options like ['table' => ['header' => false]].
  • Register custom formatters by implementing FormatterInterface and calling addFormatter(). Ideal for domain-specific output (e.g., Slack blocks, Markdown tables).
  • Use setFormat() to define a default format context-wide (e.g., json in API-like CLI tools), avoiding repeated format strings.
  • Pre-process complex objects with symfony/property-access to flatten into arrays before formatting—avoids in-formatter reflection overhead.
  • Combine with symfony/console’s OutputInterface to stream large datasets incrementally (though note the library lacks built-in streaming support).

Gotchas and Tips

  • Formatter options must be nested: ['json' => ['pretty_print' => true]], not ['pretty_print' => true]—a frequent source of silent misformatting.
  • The csv formatter fails on non-string scalars; cast all values explicitly ((string) $value) or sanitize in a pre-formatter transform layer.
  • hasFormatter($name) is essential before calling format(), as invalid format names silently produce empty output or fallback to null.
  • Custom formatters must avoid throwing exceptions inside format()—errors may be swallowed by the manager’s try/catch block. Log internally instead.
  • Given the low stars (196) and moderate score, audit commits/PRs for activity; consider vendor-forking if long-term maintenance is critical, especially for security or format updates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests