interitty/console

Extension of the standard Symfony/Console by some other features that are specific for use in the Interitty projects.

v1.0.6 2024-05-19 20:32 UTC

This package is auto-updated.

Last update: 2024-05-19 18:33:45 UTC


README

Extension of the standard Symfony/Console by some other features that are specific for use in the Interitty projects.

Requirements

Installation

The best way to install interitty/console is using Composer:

composer require interitty/console

Features

The Interitty/Console provides some additional features to the standard Symfony/Console library.

Console output

The BaseCommand class provides write and writeError methods that allow writing to standard output respectively to standard error output without the need to transmit the OutputInterface object to every method.

protected function foo(): void
{
    // outputs multiple lines to the console (adding PHP_EOL at the end of each line)
    $this->write([
        'User Creator',
        '============',
        '',
    ]);

    // the value returned by someMethod() can be an iterator (https://php.net/iterator)
    // that generates and returns the messages with the 'yield' PHP keyword
    $this->write($this->someMethod());

    // outputs a message followed by a PHP_EOL
    $this->write('Whoa!');

    // outputs a message without adding a PHP_EOL at the end of the line
    $this->write('You are about to ', false);
    $this->write('create a user.', false);

    // outputs a message to standard error output
    $this->writeError('<error>big bada bum</error>');
}

This is possible thanks to stored InputInterface and OutputInterface objects that are accessible via getInput, getOutput, and getErrorOutput methods.

Exception processor

When the Exception or any Throwable object was thrown in the execute process, there is a standard processException method that converts the exception message to a standard error output message. It also dumps a trace log when the Debug verbosity mode is set.

ProgressBar factory

The factory method createProgressBar is available for easier access to the progress bar.