Cleanup of some console commands

This commit is contained in:
Nabeel Shahzad
2017-12-29 10:23:42 -06:00
parent a5c5518a12
commit 5ec99167e8
7 changed files with 131 additions and 52 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Console;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class BaseCommand extends Command
{
/**
* Streaming file read
* @param $filename
* @return \Generator
*/
public function readFile($filename)
{
$fp = fopen($filename, 'rb');
while (($line = fgets($fp)) !== false) {
$line = rtrim($line, "\r\n");
if ($line[0] === ';') {
continue;
}
yield $line;
}
fclose($fp);
}
/**
* @param $cmd
*/
public function runCommand($cmd)
{
if (is_array($cmd))
$cmd = join(' ', $cmd);
$this->info('Running "' . $cmd . '"');
$process = new Process($cmd);
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
echo $buffer;
} else {
echo $buffer;
}
});
}
}