PlumConsole integrates the Symfony Console component into Plum. Plum is a data processing pipeline for PHP.
Developed by Florian Eckerstorfer in Vienna, Europe.
You can install Plum using Composer.
$ composer require plumphp/plum-consolePlease refer to the Plum documentation for more information about Plum in general.
PlumConsole currently contains two writers: ConsoleProgressWriter and
ConsoleTableWriter. Both are intended to be used in an application that use the
Symfony Console component. In addition it
provides ExceptionFormatter, which helps you printing nice error messages to users.
Plum\PlumConsole\ConsoleProgressWriter displays the progress of a workflow in the console.
use Plum\PlumConsole\ConsoleProgressWriter;
use Symfony\Component\Console\Helper\ProgressBar;
// ...
// $output is an instance of Symfony\Component\Console\Output\OutputInterface
// $reader is an instance of Plum\Plum\Reader\ReaderInterface
$writer = new ConsoleProgressWriter(new ProgressBar($output, $reader->count()));Plum\PlumConsole\ConsoleTableWriter outputs the processed data as table in the console.
use Plum\PlumConsole\ConsoleTableWriter;
use Symfony\Component\Console\Helper\Table;
// ...
// $output is an instance of Symfony\Component\Console\Output\OutputInterface
$writer = new ConsoleTableWriter(new Table($output));
// ConsoleTableWriter can automatically detect and set the headers
$writer->autoDetectHeader();
// Headers can also be set manually. This is required when the item is an object
$writer->setHeader(['Country', 'City']);Plum does offer the option to catch exceptions. When this option is active the workflow can resume processing even if
an item is causing errors. However, you have to manually output exceptions, which can be a tedious process.
Plum\PlumConsole\ExceptionFormatter can help you printing exceptions.
The granularity of the information can be controlled using the --verbose flag of Symfony Console. By default, the
exception messages will be printed when the application is invoked using --verbose or -v and the messages and
stack traces are printed when using -vv.
use Plum\Plum\Workflow;
use Plum\PlumConsole\ExceptionFormatter;
$workflow = Workflow(['resumeOnError' => true]);
// Build workflow
$result = $workflow->process($reader);
// $output is an instance of Symfony\Component\Console\Output\OutputInterface
$formatter = new ExceptionFormatter($output);
$formatter->outputExceptions($result);The formatter offers options to configure both the granularity when messages and stack traces are shown and let you
configure how they are printed. The following example shows all available options and the default values. Please note,
that messageTemplate and traceTemplate are being printed using sprintf().
use Plum\PlumConsole\ExceptionFormatter;
use Symfony\Component\Console\Output\OutputInterface;
// $output is an instance of Symfony\Component\Console\Output\OutputInterface
$formatter = new ExceptionFormatter($output, [
'minMessageVerbosity' => OutputInterface::VERBOSITY_VERBOSE,
'minTraceVerbosity' => OutputInterface::VERBOSITY_VERY_VERBOSE,
'messageTemplate' => '<error>%s</error>',
'traceTemplate' => '%s',
]);- Add support for Symfony 3
- Add
ConsoleTableWriter
- Fix Plum version
- Fix dependency to Plum
- Initial release
- Works with Plum v0.1
The MIT license applies to plumphp/plum-console. For the full copyright and license information, please view the LICENSE file distributed with this source code.

