54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace KupShop\SystemInspectionBundle\Command;
|
|
|
|
use KupShop\SystemInspectionBundle\Inspections\Compile\CompileInspectionInterface;
|
|
use KupShop\SystemInspectionBundle\InspectionWriters\ActivityLogWriter;
|
|
use KupShop\SystemInspectionBundle\InspectionWriters\ExceptionWriter;
|
|
use KupShop\SystemInspectionBundle\Util\InspectionRunner;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class InspectionCommand extends Command
|
|
{
|
|
protected static $defaultName = 'kupshop:inspection';
|
|
|
|
protected $inspectionRunner;
|
|
|
|
/**
|
|
* @required
|
|
*/
|
|
public function setInspectionRunner(InspectionRunner $inspectionRunner): void
|
|
{
|
|
$this->inspectionRunner = $inspectionRunner;
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setName('System inspection')
|
|
->setDescription('Runs specified system inspections')
|
|
->addArgument('type', InputArgument::OPTIONAL, 'What system inspection type do you want to run? [compile, user]', CompileInspectionInterface::INSPECTION_KEYWORD)
|
|
->addArgument('output', InputArgument::OPTIONAL, 'What writer will inspections use [exception, activity]', 'exception');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$output = $input->getArgument('output');
|
|
if ($output == 'activity') {
|
|
$writer = new ActivityLogWriter();
|
|
} elseif ($output == 'exception') {
|
|
$writer = new ExceptionWriter();
|
|
} else {
|
|
throw new \Exception('Invalid output parameter');
|
|
}
|
|
|
|
$type = $input->getArgument('type');
|
|
$this->inspectionRunner->runInspection($type, $writer);
|
|
|
|
return 0;
|
|
}
|
|
}
|