Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ncssl/source/src/Command/CpanelCommand.php
<?php
namespace App\Command;
use App\Service\CpanelApi\Adapter\CliAdapter;
use App\Service\CpanelApi\CpanelApi;
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:cpanel', description: 'Command for call cpanel api')]
class CpanelCommand extends Command
{
public function __construct(
private readonly CpanelApi $api,
private readonly LoggerInterface $logger,
){
parent::__construct();
}
protected function configure(): void
{
$this
->addArgument(
'module',
InputArgument::REQUIRED
)
->addArgument(
'function',
InputArgument::REQUIRED
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$adapter = $this->api->getAdapter();
if ($adapter instanceof CliAdapter) {
$adapter->setUsername($_SERVER['USER']);
}
$response = $this->api->uapiCall($input->getArgument('module'), $input->getArgument('function'));
dump($response);
return Command::SUCCESS;
} catch (\Exception $e) {
$this->logger->error(sprintf('Error occurred while generating WHM token: %s', $e->getMessage()));
return Command::FAILURE;
}
}
}
Back to Directory
File Manager