public function testSetOutputter() { // This test assumes that the format defaults to JSON. $formatter = $this->runner->getOutputter()->getFormatter(); $this->assertTrue(strpos(get_class($formatter), 'Pretty') !== false); // This test assumes that the format defaults to Bash. $this->runner->setOutputter('bash', 'php://stdout'); $formatter = $this->runner->getOutputter()->getFormatter(); $this->assertTrue(strpos(get_class($formatter), 'Bash') !== false); $this->runner->setOutputter('json', 'php://stdout'); $formatter = $this->runner->getOutputter()->getFormatter(); $this->assertTrue(strpos(get_class($formatter), 'JSON') !== false); }
/** * Gets command to run * * @param array $words Words of the command-line string to process * @return array $command_array * [RootCommand] $command * [array] $args * [array] $assoc_args */ private function getCommand($words) { $positional_args = $assoc_args = array(); foreach ($words as $arg) { if (preg_match('|^--([^=]+)=?|', $arg, $matches)) { $assoc_args[$matches[1]] = true; } else { $positional_args[] = $arg; } } $runner = new Runner(); $command_components = $runner->findCommandToRun($positional_args); if (!is_array($command_components) && array_pop($command_components) == $this->cur_word) { $command_components = $runner->findCommandToRun($positional_args); } if (is_array($command_components)) { $command_components[] = $assoc_args; } return $command_components; }
/** * Sends a request to the API * * @param string $uri URL for API request * @param string $method Request method (i.e. PUT, POST, DELETE, or GET) * @param array $arg_params Request parameters * @return \Psr\Http\Message\ResponseInterface */ private function send($uri, $method, array $arg_params = array()) { $extra_params = array('headers' => array('User-Agent' => $this->userAgent(), 'Content-type' => 'application/json'), RequestOptions::VERIFY => strpos(TERMINUS_HOST, 'onebox') === false); if ($session = Session::instance()->get('session', false)) { $extra_params['headers']['Authorization'] = "Bearer {$session}"; } $params = array_merge_recursive($extra_params, $arg_params); if (isset($params['form_params'])) { $params['json'] = $params['form_params']; unset($params['form_params']); } $params[RequestOptions::VERIFY] = strpos(TERMINUS_HOST, 'onebox') === false; $client = new Client(array('base_uri' => $this->getBaseUri(), 'cookies' => $this->fillCookieJar($params))); unset($params['cookies']); Runner::getLogger()->debug("#### REQUEST ####\nParams: {params}\nURI: {uri}\nMethod: {method}", array('params' => json_encode($params), 'uri' => $uri, 'method' => $method)); //Required objects and arrays stir benign warnings. error_reporting(E_ALL ^ E_WARNING); $request = new HttpRequest(ucwords($method), $uri, $params); error_reporting(E_ALL); $response = $client->send($request, $params); return $response; }
/** * Sets the Terminus outputter to a specific format and destination * * @param string $format Type of formatter to set on outputter * @param string $destination Where output will be written to * @return void */ function setTerminusOutputter($destination = 'php://stdout', $format = null) { Runner::setOutputter($format, $destination); }