/** * Main runner method * * @param string[] args */ public static function main(array $args) { // Parse args $api = new RestClient('http://builds.planet-xp.net/'); $action = null; $cat = null; for ($i = 0, $s = sizeof($args); $i < $s; $i++) { if ('-?' === $args[$i] || '--help' === $args[$i]) { break; } else { if ('-a' === $args[$i]) { $api->setBase($args[++$i]); } else { if ('-v' === $args[$i]) { $cat = create(new LogCategory('console'))->withAppender(new ColoredConsoleAppender()); } else { if ('-' === $args[$i][0]) { Console::$err->writeLine('*** Unknown argument ', $args[$i]); return 128; } else { $action = $args[$i]; // First non-option is the action name break; } } } } } if (null === $action) { Console::$err->writeLine(self::textOf(\lang\XPClass::forName(\xp::nameOf(__CLASS__))->getComment())); return 1; } try { $class = \lang\reflect\Package::forName('xp.install')->loadClass(ucfirst($action) . 'Action'); } catch (\lang\ClassNotFoundException $e) { Console::$err->writeLine('*** No such action "' . $action . '"'); return 2; } // Show help if (in_array('-?', $args) || in_array('--help', $args)) { Console::$out->writeLine(self::textOf($class->getComment())); return 3; } // Perform action $instance = $class->newInstance($api); $instance->setTrace($cat); try { return $instance->perform(array_slice($args, $i + 1)); } catch (\lang\Throwable $e) { Console::$err->writeLine('*** Error performing action ~ ', $e); return 1; } }
/** * Creates a new fixture * * @param var status either an int with a status code or an exception object * @param string body default NULL * @param [:string] headers default [:] * @return webservices.rest.RestClient */ public function fixtureWith($status, $body = null, $headers = array()) { $fixture = new RestClient(); $fixture->setConnection(self::$conn->newInstance($status, $body, $headers)); return $fixture; }