server/src/app/Libraries/Sparql/GuzzleSparqlClient.php
author ymh <ymh.work@gmail.com>
Fri, 09 Jun 2017 15:22:02 +0200
changeset 531 48f5380c26d0
child 537 d2e6ee099125
permissions -rw-r--r--
Replace EasyRdf http loading with guzzle to solve proxy problems
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
531
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Libraries\Sparql;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use EasyRdf\Sparql\Client;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use EasyRdf\Sparql\Result;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
use EasyRdf\Exception;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
use EasyRdf\Format;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use EasyRdf\RdfNamespace;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Wraps a Guzzle psr7 response into a EasyRdf\Http\Response interface
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 **/
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
class ResponseWrapper {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
     * Constructor.
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
     * @param  Response     Guzzle psr7 response
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    public function __construct($response) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        $this->response = $response;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
     * Check whether the response in successful
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    public function isSuccessful()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        return ($status >= 200 && $status < 300);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
     * Check whether the response is an error
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    public function isError()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        return ($status >= 400 && $status < 600);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
     * Check whether the response is a redirection
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    public function isRedirect()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        return ($status >= 300 && $status < 400);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
     * Get the HTTP response status code
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
     * @return int
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
    public function getStatus()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        return $this->response->getStatusCode();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
     * Return a message describing the HTTP response code
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
     * (Eg. "OK", "Not Found", "Moved Permanently")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    public function getMessage()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        return $this->response->getReasonPhrase();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
     * Get the response body as string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    public function getBody()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        return $this->response->getBody();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
     * Get the raw response body (as transfered "on wire") as string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
     * If the body is encoded (with Transfer-Encoding, not content-encoding -
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
     * IE "chunked" body), gzip compressed, etc. it will not be decoded.
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    public function getRawBody()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        return $this->getBody();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
     * Get the HTTP version of the response
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    public function getVersion()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        return $this->response->getProtocolVersion();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
     * Get the response headers
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
     * @return array
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
    public function getHeaders()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        return $this->response->getHeaders();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
     * Get a specific header as string, or null if it is not set
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
     * @param string$header
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
     * @return string|array|null
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
    public function getHeader($header)
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
        $header = $this->response->getHeader($header);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        if(is_array($header) && count($header) == 1) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
            return $header[0];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
        } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
            return $header;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
     * Get all headers as string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
     * @param boolean $statusLine Whether to return the first status line (ie "HTTP 200 OK")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
     * @param string  $br         Line breaks (eg. "\n", "\r\n", "<br />")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    public function getHeadersAsString($statusLine = true, $br = "\n")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
        $str = '';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
        if ($statusLine) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
            $version = $this->getVersion();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            $message = $this->getMessage();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
            $str = "HTTP/{$version} {$status} {$message}{$br}";
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
        // Iterate over the headers and stringify them
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
        foreach ($this->getHeaders() as $name => $value) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
            if (is_string($value)) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
                $str .= "{$name}: {$value}{$br}";
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
            } elseif (is_array($value)) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
                foreach ($value as $subval) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
                    $str .= "{$name}: {$subval}{$br}";
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
                }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
        return $str;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
     * Get the entire response as string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
     * @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
    public function asString($br = "\n")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
        return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
     * Implements magic __toString()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
    public function __toString()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
        return $this->asString();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
}
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
class GuzzleSparqlClient extends Client {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
    public function __construct($httpClient, $queryUri, $updateUri = null) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
        parent::__construct($queryUri, $updateUri);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
        $this->httpClient = $httpClient;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
    private function queryUriHasParams() {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
        return strlen(parse_url($this->getQueryUri(), PHP_URL_QUERY)) > 0;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
     * Build http-client object, execute request and return a response
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
     * @param string $processed_query
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
     * @param string $type            Should be either "query" or "update"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
     * @return Http\Response|\Zend\Http\Response
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
     * @throws Exception
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
    protected function executeQuery($processed_query, $type)
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
        // Tell the server which response formats we can parse
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
        $sparql_results_types = array(
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
            'application/sparql-results+json' => 1.0,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
            'application/sparql-results+xml' => 0.8
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
        );
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
        $request_options = [];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
        $uri = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
        $method = 'GET';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
        if ($type == 'update') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
            // accept anything, as "response body of a […] update request is implementation defined"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
            // @see http://www.w3.org/TR/sparql11-protocol/#update-success
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
            $accept = Format::getHttpAcceptHeader($sparql_results_types);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
            $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
                'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
                'Content-Type' => 'application/sparql-update'
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
            ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
            $uri = $this->getUpdateUri();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
            $method = 'POST';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
            $request_options['body'] = $processed_query;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
        } elseif ($type == 'query') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
            $re = '(?:(?:\s*BASE\s*<.*?>\s*)|(?:\s*PREFIX\s+.+:\s*<.*?>\s*))*'.
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
                '(CONSTRUCT|SELECT|ASK|DESCRIBE)[\W]';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
            $result = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
            $matched = mb_eregi($re, $processed_query, $result);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
            if (false === $matched or count($result) !== 2) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
                // non-standard query. is this something non-standard?
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
                $query_verb = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
                $query_verb = strtoupper($result[1]);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
            if ($query_verb === 'SELECT' or $query_verb === 'ASK') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
                // only "results"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
                $accept = Format::formatAcceptHeader($sparql_results_types);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
            } elseif ($query_verb === 'CONSTRUCT' or $query_verb === 'DESCRIBE') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
                // only "graph"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
                $accept = Format::getHttpAcceptHeader();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
                // both
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
                $accept = Format::getHttpAcceptHeader($sparql_results_types);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
            $encodedQuery = 'query=' . urlencode($processed_query);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
            // Use GET if the query is less than 2kB
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
            // 2046 = 2kB minus 1 for '?' and 1 for NULL-terminated string on server
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
            if (strlen($encodedQuery) + strlen($this->getQueryUri()) <= 2046) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
                $delimiter = $this->queryUriHasParams() ? '&' : '?';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
                $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
                    'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
                ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
                $method = 'GET';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
                $uri = $this->getQueryUri() . $delimiter . $encodedQuery;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
                $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
                    'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
                    'Content-Type' => 'application/x-www-form-urlencoded'
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
                ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
                // Fall back to POST instead (which is un-cacheable)
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
                $method = 'POST';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
                $uri = $this->getQueryUri();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
                $request_options['body'] = $encodedQuery;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
        } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
            throw new Exception('unexpected request-type: '.$type);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
        $response = $this->httpClient->request($method, $uri, $request_options);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
        return new ResponseWrapper($response);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
    }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
}
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284