Skip to content

Instantly share code, notes, and snippets.

@shyuan
Created March 15, 2018 17:54
Show Gist options
  • Save shyuan/783b8e7801a3188b30756c95af9836e3 to your computer and use it in GitHub Desktop.
Save shyuan/783b8e7801a3188b30756c95af9836e3 to your computer and use it in GitHub Desktop.
Laravel Zero Reverse Command Read data from STDIN
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class Reverse extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'reverse { string? : A string to be reversed }';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Reverse a string ';
/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$string = $this->argument('string');
if($string === null) {
while ($string = trim(fgets(STDIN))) {
$this->info(strrev($string));
}
} else {
$this->info(strrev($string));
}
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment