File: D:/HostingSpaces/SBogers10/zipwire.komma.pro/app/Console/Commands/HouseKeeper.php
<?php
namespace App\Console\Commands;
use App\KommaApp\Documents\Kms\DocumentService;
use App\KommaApp\Kms\Core\HouseKeeping\CanDoHousekeepingInterface;
use Illuminate\Console\Command;
class HouseKeeper extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kms:housekeeper {for? : Where you wan\'t to do houskeeping for. Choices: documents}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Does housekeeping';
/**
* @var array Maps for names to concrete classes
*/
private static $forMap = [
'documents' => DocumentService::class,
];
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$for = $this->argument('for');
if(!$for) $for = null;
if($for == null)
{
$fors = array_keys(self::$forMap);
foreach($fors as $for)
{
$this->doHouseKeepingFor($for);
}
} else {
if(!in_array($for, array_keys(self::$forMap), true)) {
$this->error('Woops! I don\'t know what you mean with "'.$for.'". Choices: '.implode(',', array_keys(self::$forMap)));
return;
}
$this->doHouseKeepingFor($for);
}
}
private function doHouseKeepingFor($for)
{
$interfaces = class_implements(self::$forMap[$for]);
if(!in_array(CanDoHousekeepingInterface::class, $interfaces)) throw new \RuntimeException("Could not do housekeeping for '".$for."' since its class '".self::$forMap[$for]."' does not implement the '".CanDoHousekeepingInterface::class."'.");
self::$forMap[$for]::doHouseKeeping();
}
}