12-cactus/espinoso

View on GitHub
app/Console/Commands/SetWebhook.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php namespace App\Console\Commands;
 
use Illuminate\Console\Command;
 
class SetWebhook extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'espi:nghook';
 
/**
* The console command description.
*
* @var string
*/
protected $description = 'Set ngrok publish services as webhook';
 
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
 
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): void
{
$route = "/set-webhook";
$url = shell_exec('curl -s http://127.0.0.1:4040/status | grep -P "https://.*?ngrok.io" -oh');
$url = trim($url) . $route;
 
if ($url == $route) {
$this->error('ngrok is not running...');
return;
}
 
$data = shell_exec("wget --method=POST -q -O - {$url}");
$data == '[true]'
? $this->info('Done!')
: $this->error('something is wrong, check ./storage/logs/ to find the error');
}
}