What I have noticed is that responses from AWS PHP SDK are sometimes a single result other times an array of results.
The issue may be because of my lack of knowledge when dealing with CFSimpleXML/SimpleXML Objects.
I have tried several ways of doing this but each one is rather difficult and what I've learned is that after a while of doing things and they all seem difficult, then you are doing it wrong.
What's Happening
Example Call With describe_load_balancers
<?php
$elb = new AmazonELB();
$response = $elb->describe_load_balancers();
if ($response->isOK())
{
foreach($response->body->LoadBalancerDescriptions() AS $loadBalancer)
{
print_r($loadBalancer);
}
}
?>
If it has only one result it prints something like this:
CFSimpleXML Object
(
[member] => CFSimpleXML Object
(
[SecurityGroups] => CFSimpleXML Object
(
)
[LoadBalancerName] => LBName1
[CreatedTime] => 2012-08-01T12:22:03.910Z
...
)
)
If it has multiple results it prints something like this:
CFSimpleXML Object
(
[member] => Array
(
[0] => CFSimpleXML Object
(
[SecurityGroups] => CFSimpleXML Object
(
)
[LoadBalancerName] => LBName1
[CreatedTime] => 2012-08-01T12:22:03.910Z
...
)
[1] => CFSimpleXML Object
(
[SecurityGroups] => CFSimpleXML Object
(
)
[LoadBalancerName] => LBName2
[CreatedTime] => 2012-08-01T16:17:21.030Z
...
)
)
)
What I want if there is a single result
CFSimpleXML Object
(
[member] => Array
(
[0] => CFSimpleXML Object
(
[SecurityGroups] => CFSimpleXML Object
(
)
[LoadBalancerName] => LBName1
[CreatedTime] => 2012-08-01T12:22:03.910Z
...
)
)
)
I have tried to loop through and see if member
is an array but it still returns it as a CFSimpleXML Object so I was unable to detect the array that print_r
says is there.
I want to be able to iterate through the list and either make Models of ELBs in my code from the SimpleXML or easily iterate over the attributes.