定制 plumphp/plum-console 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

plumphp/plum-console

最新稳定版本:v0.5

Composer 安装命令:

composer require plumphp/plum-console

包简介

Integrates the Symfony Console component into Plum.

README 文档

README

Plum

PlumConsole integrates the Symfony Console component into Plum. Plum is a data processing pipeline for PHP.

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI

Developed by Florian Eckerstorfer in Vienna, Europe.

Installation

You can install Plum using Composer.

$ composer require plumphp/plum-console

Usage

Please 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.

ConsoleProgressWriter

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()));

ConsoleTableWriter

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']);

ExceptionFormatter

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',
]);

Change Log

Version 0.5 (1 March 2016)

  • Add support for Symfony 3

Version 0.4 (24 October 2015)

  • #2 Add helper to print nice exception messages
  • #3 ConsoleTableWriter can now write object items

Version 0.3 (15 May 2015)

  • Add ConsoleTableWriter

Version 0.2.1 (28 April 2015)

  • Fix Plum version

Version 0.2 (21 April 2015)

  • Fix dependency to Plum

Version 0.1 (24 March 2014)

  • Initial release
  • Works with Plum v0.1

License

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.

统计信息

  • 总下载量: 5.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-16