interitty / console
Extension of the standard Symfony/Console by some other features that are specific for use in the Interitty projects.
Requires
- php: ~8.2
- dg/composer-cleaner: ~2.2
- interitty/utils: ~1.0
- symfony/console: ~6.2
Requires (Dev)
- interitty/code-checker: ~1.0
- interitty/phpunit: ~1.0
This package is auto-updated.
Last update: 2023-09-12 22:08:13 UTC
README
Extension of the standard Symfony/Console by some other features that are specific for use in the Interitty projects.
Requirements
- PHP >= 8.2
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.