gidato / laravel-console-output
用于捕获控制台命令输出的扩展
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: 2024-09-30 01:46:53 UTC
README
这为控制台命令提供扩展,允许调用其他命令,但收集输出而不是打印到屏幕上。
由于正常输出将输出转换为字符串,这允许返回对象,前提是它们具有 __toString() 方法
安装
composer require gidato/laravel-console-output
示例使用
<?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();
}
}
在这些调用命令中的每一个,都返回底层命令的响应,并可进行检查。
然后可以通过使用 getLines() 方法从响应中检索输出。
许可证
本软件是开源软件,根据MIT许可证许可。