public function save()
    {
        if (empty($this->attributes->guid)) {
            $this->attributes->guid = $this->createGuid();
        }

        // expand link template
        $urn = self::URN_SAVE;
        $link = $this->edit($urn);
        if (!$link) {
            throw new LinkException("Unable to find link $urn - have you loaded the document yet?");
        }
        $url = $link->expand(array('guid' => $this->attributes->guid));

        // create a saveable version of this doc
        $json = new \StdClass();
        $json->version = $this->version;
        $json->attributes = $this->attributes;
        $json->links = new \StdClass();
        foreach ($this->links as $relType => $links) {
            if (!in_array($relType, self::$_staticLinkNames)) {
                $json->links->$relType = $links;
            }
        }

        // remote save
        $resp = $this->_request('put', $url, $json);
        if (empty($resp->url)) {
            $data = ['url' => $url, 'body' => json_encode($json)];
            throw new RemoteException('Invalid PUT response missing url!', $data);
        }

        // re-load doc
        $this->href = $resp->url;
        $this->load();
        return $this;
    }
public function save()
    {
        if (empty($this->attributes->guid)) {
            $this->attributes->guid = $this->createGuid();
        }

        // expand link template
        $urn = self::URN_SAVE;
        $link = $this->edit($urn);
        if (!$link) {
            throw new LinkException("Unable to find link $urn - have you loaded the document yet?");
        }
        $url = $link->expand(array('guid' => $this->attributes->guid));

        // create a saveable version of this doc
        $json = new \StdClass();
        $json->version = $this->version;
        $json->attributes = $this->attributes;
        $json->links = new \StdClass();
        foreach ($this->links as $relType => $links) {
            if (!in_array($relType, self::$_staticLinkNames)) {
                $json->links->$relType = $links;
            }
        }

        // remote save
        $resp = $this->_request('put', $url, $json);
        if (empty($resp->url)) {
            $data = ['url' => $url, 'body' => json_encode($json)];
            throw new RemoteException('Invalid PUT response missing url!', $data);
        }

        // re-load doc
        $this->href = $resp->url;
        $this->load();
        return $this;
    }
public function save ( ) { if ( empty ( $ this -> attributes -> guid ) ) { $ this -> attributes -> guid = $ this -> createGuid ( ) ; } // expand link template $ urn = self :: URN_SAVE ; $ link = $ this -> edit ( $ urn ) ; if ( ! $ link ) { throw new LinkException ( "Unable to find link $urn - have you loaded the document yet?" ) ; } $ url = $ link -> expand ( array ( 'guid' => $ this -> attributes -> guid ) ) ; // create a saveable version of this doc $ json = new \ StdClass ( ) ; $ json -> version = $ this -> version ; $ json -> attributes = $ this -> attributes ; $ json -> links = new \ StdClass ( ) ; foreach ( $ this -> links as $ relType => $ links ) { if ( ! in_array ( $ relType , self :: $ _staticLinkNames ) ) { $ json -> links -> $ relType = $ links ; } } // remote save $ resp = $ this -> _request ( 'put' , $ url , $ json ) ; if ( empty ( $ resp -> url ) ) { $ data = [ 'url' => $ url , 'body' => json_encode ( $ json ) ] ; throw new RemoteException ( 'Invalid PUT response missing url!' , $ data ) ; } // re-load doc $ this -> href = $ resp -> url ; $ this -> load ( ) ; return $ this ; }
Persist this document to the remote server

@return self
Persist this document to the remote server