mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Commands now use provider DI
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Interfaces\SpeedtestProvider;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SpeedtestCommand extends Command
|
||||
@@ -21,13 +22,17 @@ class SpeedtestCommand extends Command
|
||||
*/
|
||||
protected $description = 'Performs a new speedtest';
|
||||
|
||||
private SpeedtestProvider $speedtestProvider;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(SpeedtestProvider $speedtestProvider)
|
||||
{
|
||||
$this->speedtestProvider = $speedtestProvider;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -42,12 +47,12 @@ class SpeedtestCommand extends Command
|
||||
|
||||
$results = SpeedtestHelper::runSpeedtest(false, false);
|
||||
|
||||
if(!is_object($results)) {
|
||||
if (!is_object($results)) {
|
||||
$this->error('Something went wrong running the speedtest.');
|
||||
exit();
|
||||
}
|
||||
|
||||
if(property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
|
||||
if (property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
|
||||
$this->error('Something went wrong running the speedtest.');
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Interfaces\SpeedtestProvider;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
@@ -22,13 +23,17 @@ class SpeedtestLatestCommand extends Command
|
||||
*/
|
||||
protected $description = 'Returns the latest speedtest result';
|
||||
|
||||
private SpeedtestProvider $speedtestProvider;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(SpeedtestProvider $speedtestProvider)
|
||||
{
|
||||
$this->speedtestProvider = $speedtestProvider;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -41,8 +46,8 @@ class SpeedtestLatestCommand extends Command
|
||||
{
|
||||
$latest = SpeedtestHelper::latest();
|
||||
|
||||
if($latest) {
|
||||
if($latest->scheduled) {
|
||||
if ($latest) {
|
||||
if ($latest->scheduled) {
|
||||
$extra = '(scheduled)';
|
||||
} else {
|
||||
$extra = '(manual)';
|
||||
@@ -50,7 +55,7 @@ class SpeedtestLatestCommand extends Command
|
||||
|
||||
$this->info('Last speedtest run at: ' . $latest->created_at . ' ' . $extra);
|
||||
|
||||
if($latest->failed) {
|
||||
if ($latest->failed) {
|
||||
$this->error('Speedtest failed');
|
||||
} else {
|
||||
$this->info('Ping: ' . $latest->ping . ' ms');
|
||||
|
||||
@@ -18,20 +18,11 @@ class SpeedtestServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (File::exists(env('DB_DATABASE'))) {
|
||||
if (Schema::hasTable('settings')) {
|
||||
switch (SettingsHelper::get('speedtest_provider')) {
|
||||
case 'ookla':
|
||||
default:
|
||||
$this->app->singleton(
|
||||
SpeedtestProvider::class,
|
||||
function () {
|
||||
return new OoklaTester();
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
$this->app->singleton(
|
||||
SpeedtestProvider::class,
|
||||
function () {
|
||||
return new OoklaTester();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user