gidato/laravel-console-output

用于捕获控制台命令输出的扩展

v0.1.0 2020-02-06 16:10 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许可证许可。