PHP code example of plumphp / plum-console

1. Go to this page and download the library: Download plumphp/plum-console library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

plumphp / plum-console example snippets


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

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 

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

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