public static function fromXML(SimpleXMLElement $xml) { $context = new ApiContext(); $context->setDefault($xml['default'] == "true"); $context->setId((string) $xml['id']); $context->setStatus(Status::fromXML($xml->status)); $context->setMaxRateLimitTPMThreshold((int) $xml->maxRateLimitTPMThreshold); $context->setMaxRateLimitTPMWarning((int) $xml->maxRateLimitTPMWarning); $context->setMaxRateLimitTPSThreshold((int) $xml->maxRateLimitTPSThreshold); $context->setMaxRateLimitTPSWarning((int) $xml->maxRateLimitTPSWarning); if (!empty($xml->loadBalancing)) { $context->setLoadBalancing(LoadBalancing::fromXML($xml->loadBalancing)); } $ths = array(); foreach ($xml->targetHosts->targetHost as $targetHostXML) { $targetHost = TargetHost::fromXML($targetHostXML); $ths[] = $targetHost; } $context->setTargetHosts($ths); return $context; }
/** * This function will guarantee that an api object exists in the * view object and in the flowscope. * * This function will set a null apiid in the view and flowscope if * this is a new api. * * @param $action * @param $flowScope */ function fill_form($action, &$flowScope) { $registry = Zend_Registry::getInstance(); $translate = $registry->get("Zend_Translate"); $apiid = $this->_getParam("id"); if (!isset($flowScope["api"])) { if ($apiid === "create") { $flowScope["apiid"] = null; $api = new Api(); $api->setStatus(Status::$ACTIVE); $provAuth = new ProvisionAuthentication(); $provAuth->setAuths(array(AuthType::$NOAUTH)); $api->setAuthentication($provAuth); $context = new ApiContext(); $context->setId("actx"); $context->setMaxRateLimitTPMThreshold(-1); $context->setMaxRateLimitTPMWarning(-1); $context->setMaxRateLimitTPSWarning(-1); $context->setMaxRateLimitTPSThreshold(-1); $api->setContexts(array($context)); $methods = array("GET", "POST", "PUT", "DELETE"); $api->setAllowedHttpMethods($methods); $flowScope["api"] = $api; } else { $flowScope["apiid"] = $apiid; try { $api = $this->getManager()->getApi($apiid); $flowScope["api"] = $api; $flowScope["relatedProperties"] = JsonPropertyPrinter::getRelatedFromApi($api); } catch (Exception $e) { $this->_helper->FlashMessenger($translate->translate("Error fetching api ") . $apiid . " : " . $e->getMessage()); $this->_helper->redirector("index", "api"); } } } if (!isset($flowScope["validationErrors"])) { $flowScope["validationErrors"] = array(); } }
public static function fromXML(SimpleXMLElement $xml) { // LoggerInterface::log("api xml: " . print_r($xml->saveXML(), true), LoggerInterface::DEBUG); $api = new Api(); $api->setId((string) $xml->id); $api->setDisplayName((string) $xml->displayName); $api->setVersion((string) $xml->version); $api->setType(ApiType::fromXML($xml->type)); $api->setEndpoint((string) $xml->endpoint); $api->setAuthentication(ProvisionAuthentication::fromXML($xml->authentication)); $api->setTdrEnabled($xml->tdrEnabled->enabled == 'true' ? true : false); $api->setTdrOnLimitReached((string) $xml->tdrOnLimitReached['type']); $api->setTdrOnUse((string) $xml->tdrOnUse['type']); $api->setStatus((string) $xml->status); $v = Validation::fromXML($xml->validation); if ($v !== null) { $api->setValidation($v); } $api->setSubscriptionStep((string) $xml->subscriptionStep); $api->setNotificationFormat((string) $xml->notificationFormat); $https = self::get_bool_value((string) $xml->https); if ($https) { $api->setHttps(HTTPSType::fromXML($xml->https)); } else { $httpsType = new HTTPSType(); $httpsType->setEnabled(false); $api->setHttps($httpsType); } $contexts = array(); foreach ($xml->contexts->context as $contextXML) { $context = ApiContext::fromXML($contextXML); $contexts[] = $context; } $api->setContexts($contexts); $api->setTdrData(TdrData::fromXML($xml->tdr)); if ($xml->properties && $xml->properties->property) { foreach ($xml->properties->property as $prop) { $api->properties[(string) $prop['name']] = (string) $prop; } } $api->setHeaderTransformationEnabled(current($xml->headerTransEnabled) == "true"); if ($xml->headerTransformations && $xml->headerTransformations->headerTransformation) { foreach ($xml->headerTransformations->headerTransformation as $transform) { $api->headerTransformations[] = HeaderTransformation::fromXML($transform); } } if ($xml->allowedHttpMethods && $xml->allowedHttpMethods->httpMethod) { foreach ($xml->allowedHttpMethods->httpMethod as $method) { $api->allowedHttpMethods[] = current($method); } } return $api; }
/** * @Given /^I request a token with a (.*) username, (.*) password, (.*) grand_type, (.*) client_id and (.*) client_secret$/ */ public function iRequestATokenWithAUsernamePasswordGrand_typeClient_idAndClient_secret($username, $password, $grand_type, $client_id, $client_secret) { // $parameter["{$username}_username"] // $parameter["{$password}_password"] // $parameter["{$grand_type}_grand_type"] // $parameter["{$client_id}_client_id"] // $parameter["{$client_secret}_client_secret"] $my_api = new test_API("test.api.com"); try { self::$api_response = $my_api->getToken(self::$parameter["{$grand_type}_grand_type"], self::$parameter["{$username}_username"], self::$parameter["{$password}_password"], self::$parameter["{$client_id}_client_id"], self::$parameter["{$client_secret}_client_secret"]); //var_dump(self::$api_response); } catch (Exception $e) { // Process the error throw new Exception($e->getMessage()); } }