arrayToXML() public static method

Straightforward val unless there are numeric keys, in which case, the parent key is singularised and used.
public static arrayToXML ( array $array, null $key_override = null ) : string
$array array
$key_override null
return string
Ejemplo n.º 1
0
 /**
  * Function to save properties directly which do not update via a POST
  *
  * This is called automatically from the save method for things like adding contacts to ContactGroups
  *
  * @param Object $object
  * @throws Exception
  */
 private function savePropertiesDirectly(Object $object)
 {
     foreach ($object::getProperties() as $property_name => $meta) {
         if ($meta[Object::KEY_SAVE_DIRECTLY] && $object->isPropertyDirty($property_name)) {
             //Then actually save
             $property_objects = $object->{$property_name};
             $property_type = get_class(current($property_objects));
             $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI()));
             $request = new Request($this, $url, Request::METHOD_PUT);
             $property_array = array();
             foreach ($property_objects as $property_object) {
                 $property_array[] = $property_object->toStringArray();
             }
             $root_node_name = Helpers::pluralize($property_type::getRootNodeName());
             $request->setBody(Helpers::arrayToXML(array($root_node_name => $property_array)));
             $request->send();
             $response = $request->getResponse();
             foreach ($response->getElements() as $element_index => $element) {
                 if ($response->getErrorsForElement($element_index) === null) {
                     $property_objects[$element_index]->fromStringArray($element);
                     $property_objects[$element_index]->setClean();
                 }
             }
             //Set it clean so the following save might have nothing to do.
             $object->setClean($property_name);
         }
     }
 }