XeroPHP\Application::savePropertiesDirectly PHP Method

savePropertiesDirectly() private method

This is called automatically from the save method for things like adding contacts to ContactGroups
private savePropertiesDirectly ( Object $object )
$object XeroPHP\Remote\Object
    private function savePropertiesDirectly(Remote\Object $object)
    {
        foreach ($object::getProperties() as $property_name => $meta) {
            if ($meta[Remote\Object::KEY_SAVE_DIRECTLY] && $object->isDirty($property_name)) {
                //Then actually save
                $property_objects = $object->{$property_name};
                /** @var Object $property_type */
                $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 = [];
                /** @var Object[] $property_objects */
                foreach ($property_objects as $property_object) {
                    $property_array[] = $property_object->toStringArray();
                }
                $root_node_name = Helpers::pluralize($property_type::getRootNodeName());
                $request->setBody(Helpers::arrayToXML([$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);
            }
        }
    }