/** * Lists all API services * * @param Console\Input\InputInterface $input The input interface * @param Console\Output\OutputInterface $output The output interface * @see Console\Command\Command */ protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $classNames = ServiceManager::getInstance()->getRegisteredServices(); $services = array(); // Stores the maximum length, for nice console formatting $maxLength = 0; foreach ($classNames as $className) { $reflector = new ServiceReflector($className); if (strlen($reflector->getName()) > $maxLength) { $maxLength = strlen($reflector->getName()); } $services[] = $reflector; } $output->writeln("<comment>PartKeepr Services:</comment>"); $output->writeln(""); foreach ($services as $service) { $name = str_pad($service->getName(), $maxLength); $output->writeln(sprintf("<info>%s</info> %s", $name, $service->getDescription())); } }
use PartKeepr\PartKeepr; include "../src/backend/PartKeepr/PartKeepr.php"; PartKeepr::initialize(""); ServiceManager::getInstance()->initialize(); ServiceManager::getInstance()->sendHeaders(); $timingStart = microtime(true); try { $request = $_REQUEST; if (array_key_exists("parameters", $_REQUEST)) { $request["parameters"] = json_decode($_REQUEST["parameters"], true); } else { $request["parameters"] = $_REQUEST; } $response = array(); $response["status"] = "ok"; $response["response"] = ServiceManager::getInstance()->call($request); $response["timing"] = microtime(true) - $timingStart; } catch (PartKeepr\Util\SerializableException $e) { $response = array(); $response["status"] = "error"; $response["exception"] = $e->serialize(); $response["timing"] = microtime(true) - $timingStart; } catch (\Exception $e) { $response = array(); $response["status"] = "systemerror"; $response["exception"] = get_class($e); $response["message"] = $e->getMessage(); $response["backtrace"] = $e->getTraceAsString(); $response["timing"] = microtime(true) - $timingStart; } if (array_key_exists("type", $_REQUEST) && strtolower($_REQUEST["type"]) == "jsonp") {