![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/zendesk/zendesk_api_client_php/src/Zendesk/Console/ |
<?php namespace Zendesk\Console; use Psy\Configuration; use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Zendesk\API\Exceptions\ApiResponseException; use Zendesk\API\HttpClient; class ConsoleCommand extends Command { /** * Configure the command options. * * @return void */ protected function configure() { $this ->setName('console') ->setDescription('Test out features of the php api client.') ->addArgument('subdomain', InputArgument::OPTIONAL) ->addArgument('username', InputArgument::OPTIONAL) ->addArgument('token', InputArgument::OPTIONAL); } /** * Execute the command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @throws RuntimeException * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $config = new Configuration; $client = new HttpClient($input->getArgument('subdomain')); $client->setAuth('basic', [ 'username' => $input->getArgument('username'), 'token' => $input->getArgument('token') ]); try { $data = $client->users()->me(); $config->setStartupMessage( '<fg=green>Hi ' . $data->user->name . '. An instance of HttpClient using your credentials is stored on $client variable.</>' ); } catch (ApiResponseException $e) { $config->setStartupMessage('<fg=red>Invalid client credentials</>'); } $shell = new Shell($config); $shell->setScopeVariables(compact('client')); $shell->run(); } }