Commands now use provider DI

This commit is contained in:
Henry Whitaker
2021-03-07 13:45:29 +00:00
parent 85d2d87e53
commit 2861196cff
3 changed files with 22 additions and 21 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Helpers\SpeedtestHelper; use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use Illuminate\Console\Command; use Illuminate\Console\Command;
class SpeedtestCommand extends Command class SpeedtestCommand extends Command
@@ -21,13 +22,17 @@ class SpeedtestCommand extends Command
*/ */
protected $description = 'Performs a new speedtest'; protected $description = 'Performs a new speedtest';
private SpeedtestProvider $speedtestProvider;
/** /**
* Create a new command instance. * Create a new command instance.
* *
* @return void * @return void
*/ */
public function __construct() public function __construct(SpeedtestProvider $speedtestProvider)
{ {
$this->speedtestProvider = $speedtestProvider;
parent::__construct(); parent::__construct();
} }

View File

@@ -3,6 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Helpers\SpeedtestHelper; use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@@ -22,13 +23,17 @@ class SpeedtestLatestCommand extends Command
*/ */
protected $description = 'Returns the latest speedtest result'; protected $description = 'Returns the latest speedtest result';
private SpeedtestProvider $speedtestProvider;
/** /**
* Create a new command instance. * Create a new command instance.
* *
* @return void * @return void
*/ */
public function __construct() public function __construct(SpeedtestProvider $speedtestProvider)
{ {
$this->speedtestProvider = $speedtestProvider;
parent::__construct(); parent::__construct();
} }

View File

@@ -18,20 +18,11 @@ class SpeedtestServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
if (File::exists(env('DB_DATABASE'))) {
if (Schema::hasTable('settings')) {
switch (SettingsHelper::get('speedtest_provider')) {
case 'ookla':
default:
$this->app->singleton( $this->app->singleton(
SpeedtestProvider::class, SpeedtestProvider::class,
function () { function () {
return new OoklaTester(); return new OoklaTester();
} }
); );
break;
}
}
}
} }
} }