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

<?php

namespace App\Command;

use App\Service\NcGatewayApi\NcGatewayApi;
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:gateway-api', description: 'Command for call gateway api')]
class GatewayApiCommand extends Command
{
    public function __construct(
        private readonly NcGatewayApi $ncGatewayApi,
        private readonly LoggerInterface $logger,
    ){
        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->addArgument(
                'function',
                InputArgument::REQUIRED,
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        try {
            $response = $this->ncGatewayApi->{$input->getArgument('function')}();
            dump($response);
        } catch (\Exception $e) {
            $this->logger->error(sprintf('Error occurred get list request: %s', $e->getMessage()));

            return Command::FAILURE;
        }

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