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

<?php

namespace App\Command;

use App\Service\PluginGateway\NcCoreApi;
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:nc-core-api', description: 'Command for call nc core api')]
class NcCoreApiCommand extends Command
{
    public function __construct(
        private readonly NcCoreApi $ncCoreApi,
        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->ncCoreApi->{$input->getArgument('function')}();
            dump($response);

            return Command::SUCCESS;
        } catch (\Exception $e) {
            $this->logger->error(sprintf('Error occurred get list request: %s', $e->getMessage()));

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