Exakat\Graph\Cypher::query PHP Method

query() public method

public query ( $query, $params = [], $load = [] )
    public function query($query, $params = array(), $load = array())
    {
        $fields = array('query' => $query);
        if (isset($params) && !empty($params)) {
            $fields['params'] = $params;
        }
        $fields_string = json_encode($fields);
        $ch = curl_init();
        static $neo4j_host, $neo4j_auth;
        if (!isset($neo4j_host)) {
            $config = \Exakat\Config::factory();
            $neo4j_host = $config->neo4j_host . ':' . $config->neo4j_port;
            if ($config->neo4j_login !== '') {
                $neo4j_auth = base64_encode($config->neo4j_login . ':' . $config->neo4j_password);
            } else {
                $neo4j_auth = '';
            }
        }
        //set the url, number of POST vars, POST data
        $headers = array('Accept: application/json;stream=true', 'Content-type: application/json', 'Content-Length: ' . strlen($fields_string));
        if (!empty($neo4j_auth)) {
            $headers[] = 'Authorization: Basic ' . $neo4j_auth;
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_URL, 'http://' . $neo4j_host . '/db/data/cypher');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
        //execute post
        $result = curl_exec($ch);
        //close connection
        curl_close($ch);
        if (isset($result->message)) {
            throw new \Exception($result->message);
        }
        return json_decode($result);
    }