ConsoleAdditions
1.0.0
讓 Symfony Console 的使用變得更加出色的工具。
該軟體包可在 Packagist 上找到:
composer require efrane/console-additions
Batch
此類別提供 Symfony 控制台應用程式的批次命令。當部署或更新腳本編寫為控制台命令(按設定順序呼叫許多其他命令,例如快取更新、資料庫遷移等)時,這非常有用。
Command::execute
中的用法:
EFrane ConsoleAdditions Command Batch:: create ( $ this -> getApplication (), $ output )
-> add ( ' my:command --with-option ' )
-> add ( ' my:other:command for-this-input ' )
-> run ();
外殼命令
批次可以是一組相互交織的控制台應用程式和系統 shell 命令。這是一項進階功能,需要symfony/process
套件作為附加相依性。
由於 shell 命令在內部建立Process
對象,因此Batch
API 公開了用於新增 shell 命令的方法:
addShell
使用給定配置添加進程(有關詳細信息,請參閱 Batch::addShell)addShellCb(string $cmd, callable $cb)
建立進程並將其傳遞給回呼以進行進一步配置。當所需的命令需要某種製程管道時,這尤其有用。消除錯誤
可以運行一批命令而不引發異常。
此軟體包提供額外的控制台輸出介面:
FileOutput
FileOutputs 將所有資料寫入檔案流並具有具體的風格:
NativeFileOutput
使用本機 PHP 檔案流功能,因此對於本地目標來說是一個不錯的選擇,並且根據您的伺服器 PHP 串流協定配置,它甚至可能足以滿足遠端目標。
另一方面, FlysystemFileOutput
將串流資料傳遞到league/flysystem
適配器,從而能夠將該資料傳送至任何 Flysystem 支援的目的地,即 S3、Dropbox、FTP 等。
MultiplexedOutput
MultiplexedOutput 可用於將多個輸出介面組合為一個輸出介面。這是文件輸出的邏輯伴侶,因為通常人們可能希望將輸出發送到使用者的控制台和其他一些目的地。內部的簡單設定可能如下所示:
class Command extends Symfony Component Console Command {
public function execute ( InputInterface $ input , OutputInterface $ output ) {
// send output to multiple destinations
$ output = new EFrane ConsoleAdditions Output MultiplexedOutput ([
$ output ,
new EFrane ConsoleAdditions Output NativeFileOutput ( ' command.log ' )
]);
// normal console command
}
}