定制 skulich/laravel-command-output-buffer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

skulich/laravel-command-output-buffer

最新稳定版本:v1.0.0

Composer 安装命令:

composer require skulich/laravel-command-output-buffer

包简介

A trait for buffering Artisan Command Output in Laravel

README 文档

README

Latest Version on Packagist PHP Version Require Laravel Version Run Tests Code Coverage License Total Downloads

A trait for buffering Artisan Command Output in Laravel. Inspired by PHP's ob_start() / ob_flush().

Use cases:

  • Conditional output — accumulate output during command execution, then decide to show it (flush) or discard it (clean) based on the result
  • Deferred output — collect output and display it all at once at the right moment

Installation

composer require skulich/laravel-command-output-buffer

Usage

Add the OutputBuffer trait to your Artisan command:

use Illuminate\Console\Command;
use SKulich\LaravelCommandOutputBuffer\Console\Concerns\OutputBuffer;

class ProcessDataCommand extends Command
{
    use OutputBuffer;

    protected $signature = 'app:process-data';

    public function handle(): int
    {
        $this->obStart();

        $this->line('Processing item 1...');
        $this->line('Processing item 2...');
        $this->v('Verbose detail');

        if ($this->hasErrors()) {
            $this->obFlush();  // show accumulated output — something went wrong

            return self::FAILURE;
        }

        $this->obClean();  // discard output — all ok

        return self::SUCCESS;
    }
}

Deferred output

Pass a variable to obStart() to auto-flush when it goes out of scope:

public function handle(): int
{
    $this->obStart($defer);

    $this->info('Step 1 done');
    $this->info('Step 2 done');

    return self::SUCCESS;
    // buffer is automatically flushed here when $defer is destroyed
}

API

All ob* methods are protected — they are meant to be called from within the command itself.

Method Description
obStart() Start buffering output
obStart(&$defer) Start buffering with auto-flush on scope exit
obPause() Pause buffering — output goes directly to console
obStop() Stop buffering and clear the buffer
obClean() Clear the buffer without stopping
obFlush() Output all buffered lines to the console
v($string, $style) Buffer a line only when -v (verbose)
vv($string, $style) Buffer a line only when -vv (very verbose)
vvv($string, $style) Buffer a line only when -vvv (debug)

The line() method is automatically intercepted — when buffering is active, output goes to the buffer instead of the console.

Tests

Run the entire test suite:

composer test

Changelog

Please see CHANGELOG for more information.

Contributing

Please see CONTRIBUTING for more information.

License

The MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固