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; }
/** * @static * @param SimpleXMLElement $xml * @return Auth */ public static function fromXML(SimpleXMLElement $xml) { $auth = new Auth(); $auth->id = (string) $xml->id; $auth->apiContext = (string) $xml->apiContext['id']; $auth->authKeyAuth = AuthKeyAuth::fromXML($xml->authKeyAuth); $auth->basicAuth = BasicAuth::fromXML($xml->basicAuth); $auth->ipWhiteListAuth = IpWhiteListAuth::fromXML($xml->ipWhiteListAuth); $auth->wsseAuth = WSSEAuth::fromXML($xml->wsseAuth); $auth->policyContext = (string) $xml->policyContext['id']; $auth->status = current($xml->status); $auth->type = AuthType::fromXML($xml->type); $auth->tdrData = TdrData::fromXML($xml->tdr); if ($xml->properties && $xml->properties->property) { foreach ($xml->properties->property as $prop) { $auth->properties[(string) $prop['name']] = (string) $prop; } } if (!empty($auth->properties)) { ksort($auth->properties); } if ($xml->headerTransformations && $xml->headerTransformations->headerTransformation) { foreach ($xml->headerTransformations->headerTransformation as $transform) { $auth->headerTransformations[] = HeaderTransformation::fromXML($transform); } } return $auth; }
public static function fromXML(SimpleXMLElement $xml) { $policy = new Policy(); $policy->id = (string) $xml->id; if ($xml->apiIds->apiId) { foreach ($xml->apiIds->apiId as $apiId) { $policy->apiIds[] = current($apiId); } } if ($xml->authIds->quotaRLBucket) { foreach ($xml->authIds->quotaRLBucket as $bucket) { $policy->authIds[] = AuthIdsType::fromXML($bucket); } } if ($xml->contexts->context) { foreach ($xml->contexts->context as $contextXML) { $policy->contexts[] = Context::fromXML($contextXML); } } $policy->tdrOnLimitReached = (string) $xml->tdrOnLimitReached['type']; $policy->tdr = $xml->tdr ? TdrData::fromXML($xml->tdr) : new TdrData(); if ($xml->properties && $xml->properties->property) { foreach ($xml->properties->property as $prop) { $policy->properties[(string) $prop['name']] = (string) $prop; } } if (!empty($policy->properties)) { ksort($policy->properties); } if ($xml->headerTransformations && $xml->headerTransformations->headerTransformation) { foreach ($xml->headerTransformations->headerTransformation as $transform) { $policy->headerTransformations[] = HeaderTransformation::fromXML($transform); } } return $policy; }