Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ncssl/source/src/Command/CertificateCommand.php

<?php

namespace App\Command;

use App\Service\Certificate\Certificate;
use App\Service\Certificate\CertificateTransfer;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
    name: 'app:certificate:get',
    description: 'Command for call certificate service for get info about certificate',
)]
class CertificateCommand extends Command
{
    public function __construct(
        private readonly Certificate $certificate,
        private readonly LoggerInterface $logger,
    ){
        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->addArgument('domainName', InputArgument::REQUIRED, 'Domain name of current user')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $certificateTransfer = new CertificateTransfer([
            'userName' => $_SERVER['USER'],
            'domainName' => $input->getArgument('domainName'),
        ]);

        try {
            $response = $this->certificate->getCertificate($certificateTransfer);
            dump($response);
        } catch (\Exception $e) {
            $this->logger->error(sprintf('Error occurred get certificate request: %s', $e->getMessage()));

            return Command::FAILURE;
        }

        return Command::SUCCESS;
    }
}
Back to Directory File Manager