mpyw/streamable-console
Composer 安装命令:
composer require mpyw/streamable-console
包简介
Call interactive artisan command using arbitrary stream
README 文档
README
Call interactive artisan command using arbitrary stream.
Requirements
- PHP:
^8.2 - Laravel:
^11.0 || ^12.0 || ^13.0 - guzzlehttp/psr7:
^2.7
Note
Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.
Installing
composer require mpyw/streamable-console
Usage
Using Stream
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class QuizCommand extends Command { protected $signature = 'example:quiz'; /** * @return int */ public function handle(): int { // We need to type "no" and press Enter to pass if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } return 0; } }
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Mpyw\StreamableConsole\Streamable; class RunCommand extends Command { use Streamable; protected $signature = 'example:run'; /** * @return int */ public function handle(): int { // Type "no" and press Enter return $this->usingInputStream("no\n")->call('example:quiz'); } }
Using Infinite Input (yes command emulation)
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class QuizCommand extends Command { protected $signature = 'example:quiz'; /** * @return int */ public function handle(): int { // We need to type "no" and press Enter to pass at least for three times if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } if ($this->confirm('Is one plus one equals to three?', true)) { return 1; } return 0; } }
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Mpyw\StreamableConsole\Streamable; class RunCommand extends Command { use Streamable; protected $signature = 'example:run'; /** * @return int */ public function handle(): int { // Infinitely type "no" and press Enter return $this->usingInfiniteInput("no\n")->call('example:quiz'); } }
Note that you can use yes() as an alias of usingInfiniteInput().
统计信息
- 总下载量: 110
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-28