src/snac/client/util/ServerConnect.php
/**
     * Perform Server Query
     *
     * Uses CURL to query the server by converting the given array into JSON, sending that
     * to the back-end server via PUT, then returns the server's response as an associative
     * array.
     *
     * @param array $query Associative array of the query information to send to the
     *        back-end server
     * @return string[] The response from the server
     */
Perform Server Query
Uses CURL to query the server by converting the given array into JSON, sending that
to the back-end server via PUT, then returns the server's response as an associative
array.

@param array $query Associative array of the query information to send to the
back-end server
@return string[] The response from the server
Perform Server Query Uses CURL to query the server by converting the given array into JSON sending that to the back - end server via PUT then returns the server ' s response as an associative array . @param array $query Associative array of the query information to send to the back - end server @return string [] The response from the server
public function query($query) {
        $userQuery = array();
        if ($this->user != null)
            $userQuery["user"] = $this->user->toArray();
        $realQuery = array_merge($query, $userQuery);
        $this->logger->addDebug("Sending the following server query", $realQuery);
        $data = json_encode($realQuery);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->serverURL);
        curl_setopt($ch, CURLOPT_HTTPHEADER,
                array (
                        'Content-Type: application/json',
                        'Content-Length: ' . strlen($data)
                ));
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        $this->code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        $return = json_decode($response, true);
        if ($return == null) {
            $this->logger->addDebug("Got the following improper server response", array($response));
            return $response;
        }
        $this->logger->addDebug("Got the following server response", $return);
        if (isset($return["user"]) && $return["user"] != null) {
            $tmpUser = new \snac\data\User($return["user"]);
            if ($tmpUser != null) {
                $this->user = $tmpUser;
            }
        }
        return $return;
    }
public function query ( $ query ) { $ userQuery = array ( ) ; if ( $ this -> user != null ) $ userQuery [ " user " ] = $ this -> user -> toArray ( ) ; $ realQuery = array_merge ( $ query , $ userQuery ) ; $ this -> logger -> addDebug ( " Sending the following server query " , $ realQuery ) ; $ data = json_encode ( $ realQuery ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ this -> serverURL ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-Type: application/json' , 'Content-Length: ' . strlen ( $ data ) ) ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'PUT' ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ ch ) ; $ this -> code = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; curl_close ( $ ch ) ; $ return = json_decode ( $ response , true ) ; if ( $ return == null ) { $ this -> logger -> addDebug ( " Got the following improper server response " , array ( $ response ) ) ; return $ response ; } $ this -> logger -> addDebug ( " Got the following server response " , $ return ) ; if ( isset ( $ return [ " user " ] ) && $ return [ " user " ] != null ) { $ tmpUser = new \ snac \ data \ User ( $ return [ " user " ] ) ; if ( $ tmpUser != null ) { $ this -> user = $ tmpUser ; } } return $ return ; }
Perform Server Query
 Uses CURL to query the server by converting the given array into JSON, sending that
 to the back-end server via PUT, then returns the server's response as an associative
 array.
Perform Server Query Uses CURL to query the server by converting the given array into JSON sending that to the back - end server via PUT then returns the server ' s response as an associative array .
// Encode the query as json // Use CURL to send request to the internal server // Return the server response as associative array