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; }