server/src/app/Libraries/Sparql/GuzzleSparqlClient.php
author ymh <ymh.work@gmail.com>
Fri, 17 Nov 2017 00:06:39 +0100
changeset 556 a31f1343b913
parent 537 d2e6ee099125
permissions -rw-r--r--
Correct header and footer for backend pages
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;
537
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 531
diff changeset
     9
use GuzzleHttp\Client as GuzzleClient;
531
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
/**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * 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
    13
 **/
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
class ResponseWrapper {
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
     * Constructor.
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
     * @param  Response     Guzzle psr7 response
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    public function __construct($response) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        $this->response = $response;
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
     * 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
    27
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    public function isSuccessful()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        return ($status >= 200 && $status < 300);
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
     * 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
    38
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    public function isError()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        return ($status >= 400 && $status < 600);
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
     * 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
    49
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
     * @return boolean
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    public function isRedirect()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        return ($status >= 300 && $status < 400);
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
     * 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
    60
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
     * @return int
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    public function getStatus()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        return $this->response->getStatusCode();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
     * 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
    70
     * (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
    71
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    public function getMessage()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        return $this->response->getReasonPhrase();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
     * 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
    81
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    public function getBody()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        return $this->response->getBody();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
     * 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
    91
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
     * 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
    93
     * 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
    94
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    public function getRawBody()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        return $this->getBody();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
     * 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
   104
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
    public function getVersion()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
        return $this->response->getProtocolVersion();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
     * Get the response headers
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
     * @return array
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
    public function getHeaders()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
        return $this->response->getHeaders();
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
     * 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
   124
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
     * @param string$header
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
     * @return string|array|null
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
    public function getHeader($header)
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        $header = $this->response->getHeader($header);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
        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
   133
            return $header[0];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
            return $header;
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
     * Get all headers as string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
     * @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
   143
     * @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
   144
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    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
   148
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
        $str = '';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
        if ($statusLine) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            $version = $this->getVersion();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
            $status = $this->getStatus();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
            $message = $this->getMessage();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
            $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
   156
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
        // 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
   159
        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
   160
            if (is_string($value)) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
                $str .= "{$name}: {$value}{$br}";
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
            } elseif (is_array($value)) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
                foreach ($value as $subval) {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
                    $str .= "{$name}: {$subval}{$br}";
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
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
        return $str;
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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
     * 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
   174
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
     * @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
   176
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    public function asString($br = "\n")
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
        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
   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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
     * Implements magic __toString()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
     * @return string
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
    public function __toString()
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
        return $this->asString();
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
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
class GuzzleSparqlClient extends Client {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
537
d2e6ee099125 upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents: 531
diff changeset
   197
    public function __construct(GuzzleClient $httpClient, $queryUri, $updateUri = null) {
531
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
        parent::__construct($queryUri, $updateUri);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
        $this->httpClient = $httpClient;
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
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
    private function queryUriHasParams() {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
        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
   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
    /**
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
     * 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
   208
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
     * @param string $processed_query
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
     * @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
   211
     *
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
     * @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
   213
     * @throws Exception
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
     */
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
    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
   216
    {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
        // 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
   218
        $sparql_results_types = array(
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
            '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
   220
            '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
   221
        );
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
        $request_options = [];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
        $uri = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
        $method = 'GET';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
        if ($type == 'update') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
            // 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
   227
            // @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
   228
            $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
   229
            $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
                'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
                'Content-Type' => 'application/sparql-update'
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
            ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
            $uri = $this->getUpdateUri();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
            $method = 'POST';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
            $request_options['body'] = $processed_query;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
        } elseif ($type == 'query') {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
            $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
   238
                '(CONSTRUCT|SELECT|ASK|DESCRIBE)[\W]';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
            $result = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
            $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
   241
            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
   242
                // 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
   243
                $query_verb = null;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
                $query_verb = strtoupper($result[1]);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
            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
   248
                // only "results"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
                $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
   250
            } 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
   251
                // only "graph"
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
                $accept = Format::getHttpAcceptHeader();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
                // both
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
                $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
   256
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
            $encodedQuery = 'query=' . urlencode($processed_query);
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
            // 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
   259
            // 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
   260
            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
   261
                $delimiter = $this->queryUriHasParams() ? '&' : '?';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
                $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
                    'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
                ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
                $method = 'GET';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
                $uri = $this->getQueryUri() . $delimiter . $encodedQuery;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
            } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
                $request_options['headers'] = [
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
                    'Accept' => $accept,
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
                    '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
   271
                ];
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
                // 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
   273
                $method = 'POST';
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
                $uri = $this->getQueryUri();
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
                $request_options['body'] = $encodedQuery;
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
            }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
        } else {
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
            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
   279
        }
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
        $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
   281
        return new ResponseWrapper($response);
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
}
48f5380c26d0 Replace EasyRdf http loading with guzzle to solve proxy problems
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285