HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Kms/Core/HouseKeeping/HouseKeeper.php
<?php

namespace App\Komma\Kms\Core\HouseKeeping;

use App\Komma\Documents\Kms\DocumentService;
use App\Komma\Kms\ActionLog\ActionLogService;
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,
    ];

    /**
     * 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);
    }
}