gidato / laravel-console-output
Extensions to catch the output from console commands
v0.1.0
2020-02-06 16:10 UTC
Requires
- laravel/framework: ^6.0
- symfony/console: ^4.3.4
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2025-04-29 00:54:01 UTC
README
This provides an extensions to the console commands, to allow other commands to be called, but the output to be collected rather than printed to the screen.
As the normal output converts the output to a string, this allows objects to returned provided they have the __toString() method
Installation
composer require gidato/laravel-console-output
Example Use
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Gidato\Console\Commands\Concerns\CallsCommandsAndCollectsOutput;
class MyCommand extends Command
{
\\ include the trait
use CallsCommandsAndCollectsOutput;
.
.
.
public function handle()
{
$this->callAndCollect($response, 'another:command');
$lines = $response->getLines();
$this->callSilentAndCollect($response, 'another:command');
$lines = $response->getLines();
}
}
In each of these call commands, the response from the underlying command is returned, and can be checked.
The output can then be retrieved from the response by using the getLines() method.
License
This software is open-sourced software licensed under the MIT license.