File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/ArtisanCommands/HouseKeeper.php
<?php
namespace App\Komma\ArtisanCommands;
use App\Komma\Documents\Kms\DocumentService;
use App\Komma\Dynamic\ComponentArea\ComponentAreaService;
use App\Komma\Kms\ActionLog\ActionLogService;
use App\Komma\Kms\Core\HouseKeeping\CanDoHousekeepingInterface;
use App\Komma\Routes\RouteService;
use Illuminate\Console\Command;
class HouseKeeper extends Command implements HouseKeeperInterface
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kms:housekeeper {for? : Where you want to do houskeeping for. Choices: documents, actionlogs, html5Uploads.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Does housekeeping';
/**
* @var array Maps for names to concrete classes
*/
private static $forMap = [
'documents' => DocumentService::class,
'actionlogs' => ActionLogService::class,
'routes' => RouteService::class,
'componentArea' => ComponentAreaService::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)
{
$this->info('Houskeeping "'.ucfirst($for).'". Please wait...');
$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."'.");
}
$result = self::$forMap[$for]::doHouseKeeping();
if ($result) {
$this->info($result);
}
$this->info('Done.'.PHP_EOL);
}
}