Example #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Client Secret:', null);
     $question->setHidden(true);
     $question->setMaxAttempts(3);
     $question->setValidator(function ($value) use($input, $output) {
         if (trim($value) == '') {
             throw new \Exception('The Client Secret can not be empty');
         }
         $client = new Client(['clientId' => $input->getArgument('clientId'), 'clientSecret' => $value], null, $output);
         $client->auth();
     });
     $helper->ask($input, $output, $question);
 }
 /**
  * Creates the command execution code.
  *
  * @param string            $name
  * @param \ReflectionMethod $method
  *
  * @return \Closure
  */
 private function createCode($name, \ReflectionMethod $method)
 {
     return function (InputInterface $input, OutputInterface $output) use($name, $method) {
         $client = new Client([], null, $output);
         if ($input->getOption('token')) {
             $client->authorize($input->getOption('token'));
         }
         $methodName = $method->getName();
         $api = $client->api(strtolower($name));
         $args = (new NamedArgumentsResolver($method))->resolve(array_merge($input->getOptions(), $input->getArguments()));
         $outputClass = $this->generateOutputClassFromApiClass($api);
         $response = call_user_func_array([$api, $methodName], $args);
         if (method_exists($outputClass, $methodName) && false === $input->getOption('debug') && $response->getStatusCode() < 400) {
             (new $outputClass())->{$methodName}($output, $response);
         } elseif (!method_exists($outputClass, $methodName) || true === $input->getOption('debug')) {
             $output->writeln("Headers:\n" . print_r($response->getHeaders(), true) . "Body:\n" . print_r((string) $response->getBody(), true));
         }
     };
 }