Created
March 15, 2018 17:54
-
-
Save shyuan/783b8e7801a3188b30756c95af9836e3 to your computer and use it in GitHub Desktop.
Laravel Zero Reverse Command Read data from STDIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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